Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Apr 2019 11:20:11 +0000 (UTC)
From:      Fedor Uporov <fsu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r346267 - head/sys/fs/ext2fs
Message-ID:  <201904161120.x3GBKBhN036407@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: fsu
Date: Tue Apr 16 11:20:10 2019
New Revision: 346267
URL: https://svnweb.freebsd.org/changeset/base/346267

Log:
  ext2fs: Initial version of DTrace support.
  
  Reviewed by:    pfg, gnn
  MFC after:      1 week
  
  Differential Revision:    https://reviews.freebsd.org/D19848

Modified:
  head/sys/fs/ext2fs/ext2_alloc.c
  head/sys/fs/ext2fs/ext2_csum.c
  head/sys/fs/ext2fs/ext2_extattr.c
  head/sys/fs/ext2fs/ext2_extents.h
  head/sys/fs/ext2fs/ext2_extern.h
  head/sys/fs/ext2fs/ext2_hash.c
  head/sys/fs/ext2fs/ext2_htree.c
  head/sys/fs/ext2fs/ext2_inode.c
  head/sys/fs/ext2fs/ext2_inode_cnv.c
  head/sys/fs/ext2fs/ext2_lookup.c
  head/sys/fs/ext2fs/ext2_subr.c
  head/sys/fs/ext2fs/ext2_vfsops.c
  head/sys/fs/ext2fs/ext2_vnops.c
  head/sys/fs/ext2fs/fs.h

Modified: head/sys/fs/ext2fs/ext2_alloc.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_alloc.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_alloc.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -42,6 +42,7 @@
 #include <sys/systm.h>
 #include <sys/conf.h>
 #include <sys/vnode.h>
+#include <sys/sdt.h>
 #include <sys/stat.h>
 #include <sys/mount.h>
 #include <sys/sysctl.h>
@@ -55,6 +56,23 @@
 #include <fs/ext2fs/ext2fs.h>
 #include <fs/ext2fs/ext2_extern.h>
 
+SDT_PROVIDER_DEFINE(ext2fs);
+/*
+ * ext2fs trace probe:
+ * arg0: verbosity. Higher numbers give more verbose messages
+ * arg1: Textual message
+ */
+SDT_PROBE_DEFINE2(ext2fs, , alloc, trace, "int", "char*");
+SDT_PROBE_DEFINE3(ext2fs, , alloc, ext2_reallocblks_realloc,
+    "ino_t", "e2fs_lbn_t", "e2fs_lbn_t");
+SDT_PROBE_DEFINE1(ext2fs, , alloc, ext2_reallocblks_bap, "uint32_t");
+SDT_PROBE_DEFINE1(ext2fs, , alloc, ext2_reallocblks_blkno, "e2fs_daddr_t");
+SDT_PROBE_DEFINE2(ext2fs, , alloc, ext2_b_bitmap_validate_error, "char*", "int");
+SDT_PROBE_DEFINE3(ext2fs, , alloc, ext2_nodealloccg_bmap_corrupted,
+    "int", "daddr_t", "char*");
+SDT_PROBE_DEFINE2(ext2fs, , alloc, ext2_blkfree_bad_block, "ino_t", "e4fs_daddr_t");
+SDT_PROBE_DEFINE2(ext2fs, , alloc, ext2_vfree_doublefree, "char*", "ino_t");
+
 static daddr_t	ext2_alloccg(struct inode *, int, daddr_t, int);
 static daddr_t	ext2_clusteralloc(struct inode *, int, daddr_t, int);
 static u_long	ext2_dirpref(struct inode *);
@@ -128,8 +146,7 @@ ext2_alloc(struct inode *ip, daddr_t lbn, e4fs_daddr_t
 	}
 nospace:
 	EXT2_UNLOCK(ump);
-	ext2_fserr(fs, cred->cr_uid, "filesystem full");
-	uprintf("\n%s: write failed, filesystem is full\n", fs->e2fs_fsmnt);
+	SDT_PROBE2(ext2fs, , alloc, trace, 1, "cannot allocate data block");
 	return (ENOSPC);
 }
 
@@ -147,8 +164,10 @@ ext2_alloc_meta(struct inode *ip)
 	EXT2_LOCK(ip->i_ump);
 	blk = ext2_hashalloc(ip, ino_to_cg(fs, ip->i_number), 0, fs->e2fs_bsize,
 	    ext2_alloccg);
-	if (0 == blk)
+	if (0 == blk) {
 		EXT2_UNLOCK(ip->i_ump);
+		SDT_PROBE2(ext2fs, , alloc, trace, 1, "cannot allocate meta block");
+	}
 
 	return (blk);
 }
@@ -289,10 +308,8 @@ ext2_reallocblks(struct vop_reallocblks_args *ap)
 	 * block pointers in the inode and indirect blocks associated
 	 * with the file.
 	 */
-#ifdef DEBUG
-	printf("realloc: ino %ju, lbns %jd-%jd\n\told:",
-	    (uintmax_t)ip->i_number, (intmax_t)start_lbn, (intmax_t)end_lbn);
-#endif	/* DEBUG */
+	SDT_PROBE3(ext2fs, , alloc, ext2_reallocblks_realloc,
+	    ip->i_number, start_lbn, end_lbn);
 	blkno = newblk;
 	for (bap = &sbap[soff], i = 0; i < len; i++, blkno += fs->e2fs_fpb) {
 		if (i == ssize) {
@@ -303,9 +320,7 @@ ext2_reallocblks(struct vop_reallocblks_args *ap)
 		if (buflist->bs_children[i]->b_blkno != fsbtodb(fs, *bap))
 			panic("ext2_reallocblks: alloc mismatch");
 #endif
-#ifdef DEBUG
-		printf(" %d,", *bap);
-#endif	/* DEBUG */
+		SDT_PROBE1(ext2fs, , alloc, ext2_reallocblks_bap, *bap);
 		*bap++ = blkno;
 	}
 	/*
@@ -341,20 +356,13 @@ ext2_reallocblks(struct vop_reallocblks_args *ap)
 	/*
 	 * Last, free the old blocks and assign the new blocks to the buffers.
 	 */
-#ifdef DEBUG
-	printf("\n\tnew:");
-#endif	/* DEBUG */
 	for (blkno = newblk, i = 0; i < len; i++, blkno += fs->e2fs_fpb) {
 		ext2_blkfree(ip, dbtofsb(fs, buflist->bs_children[i]->b_blkno),
 		    fs->e2fs_bsize);
 		buflist->bs_children[i]->b_blkno = fsbtodb(fs, blkno);
-#ifdef DEBUG
-		printf(" %d,", blkno);
-#endif	/* DEBUG */
+		SDT_PROBE1(ext2fs, , alloc, ext2_reallocblks_blkno, blkno);
 	}
-#ifdef DEBUG
-	printf("\n");
-#endif	/* DEBUG */
+
 	return (0);
 
 fail:
@@ -481,8 +489,7 @@ ext2_valloc(struct vnode *pvp, int mode, struct ucred 
 
 noinodes:
 	EXT2_UNLOCK(ump);
-	ext2_fserr(fs, cred->cr_uid, "out of inodes");
-	uprintf("\n%s: create/symlink failed, no inodes free\n", fs->e2fs_fsmnt);
+	SDT_PROBE2(ext2fs, , alloc, trace, 1, "out of inodes");
 	return (ENOSPC);
 }
 
@@ -959,21 +966,24 @@ ext2_b_bitmap_validate(struct m_ext2fs *fs, struct buf
 	/* Check block bitmap block number */
 	offset = e2fs_gd_get_b_bitmap(gd) - group_first_block;
 	if (offset >= max_bit || !isset(bp->b_data, offset)) {
-		printf("ext2fs: bad block bitmap, group %d\n", cg);
+		SDT_PROBE2(ext2fs, , alloc, ext2_b_bitmap_validate_error,
+		    "bad block bitmap, group", cg);
 		return (EINVAL);
 	}
 
 	/* Check inode bitmap block number */
 	offset = e2fs_gd_get_i_bitmap(gd) - group_first_block;
 	if (offset >= max_bit || !isset(bp->b_data, offset)) {
-		printf("ext2fs: bad inode bitmap, group %d\n", cg);
+		SDT_PROBE2(ext2fs, , alloc, ext2_b_bitmap_validate_error,
+		    "bad inode bitmap", cg);
 		return (EINVAL);
 	}
 
 	/* Check inode table */
 	offset = e2fs_gd_get_i_tables(gd) - group_first_block;
 	if (offset >= max_bit || offset + fs->e2fs_itpg >= max_bit) {
-		printf("ext2fs: bad inode table, group %d\n", cg);
+		SDT_PROBE2(ext2fs, , alloc, ext2_b_bitmap_validate_error,
+		    "bad inode table, group", cg);
 		return (EINVAL);
 	}
 
@@ -1350,9 +1360,8 @@ ext2_nodealloccg(struct inode *ip, int cg, daddr_t ipr
 		start = 0;
 		loc = memcchr(&ibp[start], 0xff, len);
 		if (loc == NULL) {
-			printf("ext2fs: inode bitmap corrupted: "
-			    "cg = %d, ipref = %lld, fs = %s - run fsck\n",
-			    cg, (long long)ipref, fs->e2fs_fsmnt);
+			SDT_PROBE3(ext2fs, , alloc, ext2_nodealloccg_bmap_corrupted,
+			    cg, ipref, fs->e2fs_fsmnt);
 			brelse(bp);
 			EXT2_LOCK(ump);
 			return (0);
@@ -1401,9 +1410,7 @@ ext2_blkfree(struct inode *ip, e4fs_daddr_t bno, long 
 	ump = ip->i_ump;
 	cg = dtog(fs, bno);
 	if (bno >= fs->e2fs_bcount) {
-		printf("bad block %lld, ino %ju\n", (long long)bno,
-		    (uintmax_t)ip->i_number);
-		ext2_fserr(fs, ip->i_uid, "bad block");
+		SDT_PROBE2(ext2fs, , alloc, ext2_blkfree_bad_block, ip->i_number, bno);
 		return;
 	}
 	error = bread(ip->i_devvp,
@@ -1416,9 +1423,8 @@ ext2_blkfree(struct inode *ip, e4fs_daddr_t bno, long 
 	bbp = (char *)bp->b_data;
 	bno = dtogd(fs, bno);
 	if (isclr(bbp, bno)) {
-		printf("block = %lld, fs = %s\n",
+		panic("ext2_blkfree: freeing free block %lld, fs=%s",
 		    (long long)bno, fs->e2fs_fsmnt);
-		panic("ext2_blkfree: freeing free block");
 	}
 	clrbit(bbp, bno);
 	EXT2_LOCK(ump);
@@ -1464,8 +1470,8 @@ ext2_vfree(struct vnode *pvp, ino_t ino, int mode)
 	ibp = (char *)bp->b_data;
 	ino = (ino - 1) % fs->e2fs->e2fs_ipg;
 	if (isclr(ibp, ino)) {
-		printf("ino = %ju, fs = %s\n",
-		    ino, fs->e2fs_fsmnt);
+		SDT_PROBE2(ext2fs, , alloc, ext2_vfree_doublefree,
+		    fs->e2fs_fsmnt, ino);
 		if (fs->e2fs_ronly == 0)
 			panic("ext2_vfree: freeing free inode");
 	}
@@ -1513,26 +1519,12 @@ ext2_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t
 		start = 0;
 		loc = memcchr(&bbp[start], 0xff, len);
 		if (loc == NULL) {
-			printf("start = %d, len = %d, fs = %s\n",
+			panic("ext2_mapsearch: map corrupted: start=%d, len=%d, fs=%s",
 			    start, len, fs->e2fs_fsmnt);
-			panic("ext2_mapsearch: map corrupted");
 			/* NOTREACHED */
 		}
 	}
 	return ((loc - bbp) * NBBY + ffs(~*loc) - 1);
-}
-
-/*
- * Fserr prints the name of a filesystem with an error diagnostic.
- *
- * The form of the error message is:
- *	fs: error message
- */
-void
-ext2_fserr(struct m_ext2fs *fs, uid_t uid, char *cp)
-{
-
-	log(LOG_ERR, "uid %u on %s: %s\n", uid, fs->e2fs_fsmnt, cp);
 }
 
 int

Modified: head/sys/fs/ext2fs/ext2_csum.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_csum.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_csum.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -31,6 +31,7 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/types.h>
+#include <sys/sdt.h>
 #include <sys/stat.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
@@ -50,6 +51,14 @@
 #include <fs/ext2fs/ext2_extattr.h>
 #include <fs/ext2fs/ext2_extern.h>
 
+SDT_PROVIDER_DECLARE(ext2fs);
+/*
+ * ext2fs trace probe:
+ * arg0: verbosity. Higher numbers give more verbose messages
+ * arg1: Textual message
+ */
+SDT_PROBE_DEFINE2(ext2fs, , trace, csum, "int", "char*");
+
 #define EXT2_BG_INODE_BITMAP_CSUM_HI_END	\
 	(offsetof(struct ext2_gd, ext4bgd_i_bmap_csum_hi) + \
 	 sizeof(uint16_t))
@@ -134,8 +143,7 @@ ext2_extattr_blk_csum_verify(struct inode *ip, struct 
 
 	if (EXT2_HAS_RO_COMPAT_FEATURE(ip->i_e2fs, EXT2F_ROCOMPAT_METADATA_CKSUM) &&
 	    (header->h_checksum != ext2_extattr_blk_csum(ip, ip->i_facl, header))) {
-		printf("WARNING: bad extattr csum detected, ip=%lu - run fsck\n",
-		    (unsigned long)ip->i_number);
+		SDT_PROBE2(ext2fs, , trace, csum, 1, "bad extattr csum detected");
 		return (EIO);
 	}
 
@@ -351,8 +359,7 @@ ext2_dir_blk_csum_verify(struct inode *ip, struct buf 
 		error = ext2_dx_csum_verify(ip, ep);
 
 	if (error)
-		printf("WARNING: bad directory csum detected, ip=%lu"
-		    " - run fsck\n", (unsigned long)ip->i_number);
+		SDT_PROBE2(ext2fs, , trace, csum, 1, "bad directory csum detected");
 
 	return (error);
 }
@@ -445,8 +452,7 @@ ext2_extent_blk_csum_verify(struct inode *ip, void *da
 	calculated = ext2_extent_blk_csum(ip, ehp);
 
 	if (provided != calculated) {
-		printf("WARNING: bad extent csum detected, ip=%lu - run fsck\n",
-		    (unsigned long)ip->i_number);
+		SDT_PROBE2(ext2fs, , trace, csum, 1, "bad extent csum detected");
 		return (EIO);
 	}
 
@@ -491,8 +497,7 @@ ext2_gd_i_bitmap_csum_verify(struct m_ext2fs *fs, int 
 		calculated &= 0xFFFF;
 
 	if (provided != calculated) {
-		printf("WARNING: bad inode bitmap csum detected, "
-		    "cg=%d - run fsck\n", cg);
+		SDT_PROBE2(ext2fs, , trace, csum, 1, "bad inode bitmap csum detected");
 		return (EIO);
 	}
 
@@ -532,8 +537,7 @@ ext2_gd_b_bitmap_csum_verify(struct m_ext2fs *fs, int 
 		calculated &= 0xFFFF;
 
 	if (provided != calculated) {
-		printf("WARNING: bad block bitmap csum detected, "
-		    "cg=%d - run fsck\n", cg);
+		SDT_PROBE2(ext2fs, , trace, csum, 1, "bad block bitmap csum detected");
 		return (EIO);
 	}
 
@@ -629,7 +633,7 @@ ext2_ei_csum_verify(struct inode *ip, struct ext2fs_di
 		if (!memcmp(ei, &ei_zero, sizeof(struct ext2fs_dinode)))
 			return (0);
 
-		printf("WARNING: Bad inode %ju csum - run fsck\n", ip->i_number);
+		SDT_PROBE2(ext2fs, , trace, csum, 1, "bad inode csum");
 
 		return (EIO);
 	}

Modified: head/sys/fs/ext2fs/ext2_extattr.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_extattr.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_extattr.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -39,6 +39,7 @@
 #include <sys/endian.h>
 #include <sys/conf.h>
 #include <sys/extattr.h>
+#include <sys/sdt.h>
 
 #include <fs/ext2fs/fs.h>
 #include <fs/ext2fs/ext2fs.h>
@@ -48,6 +49,14 @@
 #include <fs/ext2fs/ext2_extattr.h>
 #include <fs/ext2fs/ext2_extern.h>
 
+SDT_PROVIDER_DECLARE(ext2fs);
+/*
+ * ext2fs trace probe:
+ * arg0: verbosity. Higher numbers give more verbose messages
+ * arg1: Textual message
+ */
+SDT_PROBE_DEFINE2(ext2fs, , trace, extattr, "int", "char*");
+
 static int
 ext2_extattr_attrnamespace_to_bsd(int attrnamespace)
 {
@@ -89,9 +98,8 @@ ext2_extattr_name_to_bsd(int attrnamespace, const char
 	 * XXX: Not all linux namespaces are mapped to bsd for now,
 	 * return NULL, which will be converted to ENOTSUP on upper layer.
 	 */
-#ifdef EXT2FS_DEBUG
-	printf("can not convert ext2fs name to bsd: namespace=%d\n", attrnamespace);
-#endif
+	SDT_PROBE2(ext2fs, , trace, extattr, 1,
+	    "can not convert ext2fs name to bsd namespace");
 
 	return (NULL);
 }

Modified: head/sys/fs/ext2fs/ext2_extents.h
==============================================================================
--- head/sys/fs/ext2fs/ext2_extents.h	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_extents.h	Tue Apr 16 11:20:10 2019	(r346267)
@@ -129,7 +129,7 @@ int ext4_ext_remove_space(struct inode *ip, off_t leng
 int ext4_ext_get_blocks(struct inode *ip, int64_t iblock,
     unsigned long max_blocks, struct ucred *cred, struct buf **bpp,
     int *allocate, daddr_t *);
-#ifdef EXT2FS_DEBUG
+#ifdef EXT2FS_PRINT_EXTENTS
 void ext4_ext_print_extent_tree_status(struct inode *ip);
 #endif
 

Modified: head/sys/fs/ext2fs/ext2_extern.h
==============================================================================
--- head/sys/fs/ext2fs/ext2_extern.h	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_extern.h	Tue Apr 16 11:20:10 2019	(r346267)
@@ -66,7 +66,6 @@ int	ext2_bmaparray(struct vnode *, daddr_t, daddr_t *,
 int	ext4_bmapext(struct vnode *, int32_t, int64_t *, int *, int *);
 void	ext2_clusteracct(struct m_ext2fs *, char *, int, e4fs_daddr_t, int);
 void	ext2_dirbad(struct inode *ip, doff_t offset, char *how);
-void	ext2_fserr(struct m_ext2fs *, uid_t, char *);
 int	ext2_ei2i(struct ext2fs_dinode *, struct inode *);
 int	ext2_getlbns(struct vnode *, daddr_t, struct indir *, int *);
 int	ext2_i2ei(struct inode *, struct ext2fs_dinode *);
@@ -80,7 +79,7 @@ int	ext2_vfree(struct vnode *, ino_t, int);
 int	ext2_vinit(struct mount *, struct vop_vector *, struct vnode **vpp);
 int	ext2_lookup(struct vop_cachedlookup_args *);
 int	ext2_readdir(struct vop_readdir_args *);
-#ifdef EXT2FS_DEBUG
+#ifdef EXT2FS_PRINT_EXTENTS
 void	ext2_print_inode(struct inode *);
 #endif
 int	ext2_direnter(struct inode *, 

Modified: head/sys/fs/ext2fs/ext2_hash.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_hash.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_hash.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -57,6 +57,7 @@
 #include <sys/systm.h>
 #include <sys/conf.h>
 #include <sys/vnode.h>
+#include <sys/sdt.h>
 #include <sys/stat.h>
 #include <sys/mount.h>
 
@@ -67,6 +68,14 @@
 #include <fs/ext2fs/ext2_mount.h>
 #include <fs/ext2fs/ext2_extern.h>
 
+SDT_PROVIDER_DECLARE(ext2fs);
+/*
+ * ext2fs trace probe:
+ * arg0: verbosity. Higher numbers give more verbose messages
+ * arg1: Textual message
+ */
+SDT_PROBE_DEFINE2(ext2fs, , trace, hash, "int", "char*");
+
 /* F, G, and H are MD4 functions */
 #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
 #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
@@ -300,6 +309,7 @@ ext2_htree_hash(const char *name, int len,
 		minor = hash[2];
 		break;
 	default:
+		SDT_PROBE2(ext2fs, , trace, hash, 1, "unexpected hash version");
 		goto error;
 	}
 

Modified: head/sys/fs/ext2fs/ext2_htree.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_htree.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_htree.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -40,6 +40,7 @@
 #include <sys/vnode.h>
 #include <sys/malloc.h>
 #include <sys/dirent.h>
+#include <sys/sdt.h>
 #include <sys/sysctl.h>
 
 #include <ufs/ufs/dir.h>
@@ -54,6 +55,14 @@
 #include <fs/ext2fs/ext2_dir.h>
 #include <fs/ext2fs/htree.h>
 
+SDT_PROVIDER_DECLARE(ext2fs);
+/*
+ * ext2fs trace probe:
+ * arg0: verbosity. Higher numbers give more verbose messages
+ * arg1: Textual message
+ */
+SDT_PROBE_DEFINE2(ext2fs, , trace, htree, "int", "char*");
+
 static void	ext2_append_entry(char *block, uint32_t blksize,
 		    struct ext2fs_direct_2 *last_entry,
 		    struct ext2fs_direct_2 *new_entry, int csum_size);
@@ -816,7 +825,8 @@ ext2_htree_add_entry(struct vnode *dvp, struct ext2fs_
 
 			if (ext2_htree_get_count(root_entires) ==
 			    ext2_htree_get_limit(root_entires)) {
-				/* Directory index is full */
+				SDT_PROBE2(ext2fs, , trace, htree, 1,
+				    "directory index is full");
 				error = EIO;
 				goto finish;
 			}

Modified: head/sys/fs/ext2fs/ext2_inode.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_inode.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_inode.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -46,6 +46,7 @@
 #include <sys/vnode.h>
 #include <sys/malloc.h>
 #include <sys/rwlock.h>
+#include <sys/sdt.h>
 
 #include <vm/vm.h>
 #include <vm/vm_extern.h>

Modified: head/sys/fs/ext2fs/ext2_inode_cnv.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_inode_cnv.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_inode_cnv.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -31,6 +31,7 @@
 #include <sys/systm.h>
 #include <sys/endian.h>
 #include <sys/lock.h>
+#include <sys/sdt.h>
 #include <sys/stat.h>
 #include <sys/vnode.h>
 
@@ -40,10 +41,18 @@
 #include <fs/ext2fs/ext2_dinode.h>
 #include <fs/ext2fs/ext2_extern.h>
 
+SDT_PROVIDER_DECLARE(ext2fs);
+/*
+ * ext2fs trace probe:
+ * arg0: verbosity. Higher numbers give more verbose messages
+ * arg1: Textual message
+ */
+SDT_PROBE_DEFINE2(ext2fs, , trace, inode_cnv, "int", "char*");
+
 #define XTIME_TO_NSEC(x)	((x & EXT3_NSEC_MASK) >> 2)
 #define NSEC_TO_XTIME(t)	(le32toh(t << 2) & EXT3_NSEC_MASK)
 
-#ifdef EXT2FS_DEBUG
+#ifdef EXT2FS_PRINT_EXTENTS
 void
 ext2_print_inode(struct inode *in)
 {
@@ -83,7 +92,7 @@ ext2_print_inode(struct inode *in)
 		printf("\n");
 	}
 }
-#endif	/* EXT2FS_DEBUG */
+#endif	/* EXT2FS_PRINT_EXTENTS */
 
 /*
  *	raw ext2 inode to inode
@@ -96,12 +105,12 @@ ext2_ei2i(struct ext2fs_dinode *ei, struct inode *ip)
 	if ((ip->i_number < EXT2_FIRST_INO(fs) && ip->i_number != EXT2_ROOTINO) ||
 	    (ip->i_number < EXT2_ROOTINO) ||
 	    (ip->i_number > fs->e2fs->e2fs_icount)) {
-		printf("ext2fs: bad inode number %ju\n", ip->i_number);
+		SDT_PROBE2(ext2fs, , trace, inode_cnv, 1, "bad inode number");
 		return (EINVAL);
 	}
 
 	if (ip->i_number == EXT2_ROOTINO && ei->e2di_nlink == 0) {
-		printf("ext2fs: root inode unallocated\n");
+		SDT_PROBE2(ext2fs, , trace, inode_cnv, 1, "root inode unallocated");
 		return (EINVAL);
 	}
 	ip->i_nlink = ei->e2di_nlink;
@@ -110,8 +119,8 @@ ext2_ei2i(struct ext2fs_dinode *ei, struct inode *ip)
 	if (EXT2_INODE_SIZE(fs) > E2FS_REV0_INODE_SIZE) {
 		if (E2FS_REV0_INODE_SIZE + ei->e2di_extra_isize >
 		    EXT2_INODE_SIZE(fs) || (ei->e2di_extra_isize & 3)) {
-			printf("ext2fs: bad extra inode size %u, inode size=%u\n",
-			    ei->e2di_extra_isize, EXT2_INODE_SIZE(fs));
+			SDT_PROBE2(ext2fs, , trace, inode_cnv, 1,
+			    "bad extra inode size");
 			return (EINVAL);
 		}
 	}
@@ -199,7 +208,7 @@ ext2_i2ei(struct inode *ip, struct ext2fs_dinode *ei)
 	ei->e2di_flags |= (ip->i_flag & IN_E4EXTENTS) ? EXT4_EXTENTS : 0;
 	if (ip->i_blocks > ~0U &&
 	    !EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_HUGE_FILE)) {
-		ext2_fserr(fs, ip->i_uid, "i_blocks value is out of range");
+		SDT_PROBE2(ext2fs, , trace, inode_cnv, 1, "i_blocks value is out of range");
 		return (EIO);
 	}
 	if (ip->i_blocks <= 0xffffffffffffULL) {

Modified: head/sys/fs/ext2fs/ext2_lookup.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_lookup.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_lookup.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -53,6 +53,7 @@
 #include <sys/vnode.h>
 #include <sys/malloc.h>
 #include <sys/dirent.h>
+#include <sys/sdt.h>
 #include <sys/sysctl.h>
 
 #include <ufs/ufs/dir.h>
@@ -66,6 +67,18 @@
 #include <fs/ext2fs/ext2_extern.h>
 #include <fs/ext2fs/fs.h>
 
+SDT_PROVIDER_DECLARE(ext2fs);
+/*
+ * ext2fs trace probe:
+ * arg0: verbosity. Higher numbers give more verbose messages
+ * arg1: Textual message
+ */
+SDT_PROBE_DEFINE2(ext2fs, , lookup, trace, "int", "char*");
+SDT_PROBE_DEFINE4(ext2fs, , trace, ext2_dirbad_error,
+    "char*", "ino_t", "doff_t", "char*");
+SDT_PROBE_DEFINE5(ext2fs, , trace, ext2_dirbadentry_error,
+    "char*", "int", "uint32_t", "uint16_t", "uint8_t");
+
 #ifdef INVARIANTS
 static int dirchk = 1;
 #else
@@ -810,10 +823,8 @@ ext2_dirbad(struct inode *ip, doff_t offset, char *how
 		    mp->mnt_stat.f_mntonname, (uintmax_t)ip->i_number,
 		    (long)offset, how);
 	else
-		(void)printf("%s: bad dir ino %ju at offset %ld: %s\n",
-		    mp->mnt_stat.f_mntonname, (uintmax_t)ip->i_number,
-		    (long)offset, how);
-
+		SDT_PROBE4(ext2fs, , trace, ext2_dirbad_error,
+		    mp->mnt_stat.f_mntonname, ip->i_number, offset, how);
 }
 
 /*
@@ -849,10 +860,9 @@ ext2_dirbadentry(struct vnode *dp, struct ext2fs_direc
 	*/
 
 	if (error_msg != NULL) {
-		printf("bad directory entry: %s\n", error_msg);
-		printf("offset=%d, inode=%lu, rec_len=%u, name_len=%u\n",
-			entryoffsetinblock, (unsigned long)de->e2d_ino,
-			de->e2d_reclen, de->e2d_namlen);
+		SDT_PROBE5(ext2fs, , trace, ext2_dirbadentry_error,
+		    error_msg, entryoffsetinblock,
+		    de->e2d_ino, de->e2d_reclen, de->e2d_namlen);
 	}
 	return error_msg == NULL ? 0 : 1;
 }
@@ -1276,7 +1286,8 @@ ext2_checkpath(struct inode *source, struct inode *tar
 
 out:
 	if (error == ENOTDIR)
-		printf("checkpath: .. not a directory\n");
+		SDT_PROBE2(ext2fs, , lookup, trace, 1,
+		    "checkpath: .. not a directory");
 	if (vp != NULL)
 		vput(vp);
 	return (error);

Modified: head/sys/fs/ext2fs/ext2_subr.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_subr.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_subr.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -41,6 +41,7 @@
 #include <sys/param.h>
 
 #include <sys/proc.h>
+#include <sys/sdt.h>
 #include <sys/systm.h>
 #include <sys/bio.h>
 #include <sys/buf.h>

Modified: head/sys/fs/ext2fs/ext2_vfsops.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_vfsops.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_vfsops.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -52,6 +52,7 @@
 #include <sys/endian.h>
 #include <sys/fcntl.h>
 #include <sys/malloc.h>
+#include <sys/sdt.h>
 #include <sys/stat.h>
 #include <sys/mutex.h>
 
@@ -67,7 +68,17 @@
 #include <fs/ext2fs/ext2_extern.h>
 #include <fs/ext2fs/ext2_extents.h>
 
+SDT_PROVIDER_DECLARE(ext2fs);
+/*
+ * ext2fs trace probe:
+ * arg0: verbosity. Higher numbers give more verbose messages
+ * arg1: Textual message
+ */
+SDT_PROBE_DEFINE2(ext2fs, , vfsops, trace, "int", "char*");
+SDT_PROBE_DEFINE2(ext2fs, , vfsops, ext2_cg_validate_error, "char*", "int");
+SDT_PROBE_DEFINE1(ext2fs, , vfsops, ext2_compute_sb_data_error, "char*");
 
+
 static int	ext2_flushfiles(struct mount *mp, int flags, struct thread *td);
 static int	ext2_mountfs(struct vnode *, struct mount *);
 static int	ext2_reload(struct mount *mp, struct thread *td);
@@ -381,48 +392,54 @@ ext2_cg_validate(struct m_ext2fs *fs)
 
 		b_bitmap = e2fs_gd_get_b_bitmap(gd);
 		if (b_bitmap == 0) {
-			printf("ext2fs: cg %u: block bitmap is zero\n", i);
+			SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
+			    "block bitmap is zero", i);
 			return (EINVAL);
 
 		}
 		if (b_bitmap <= last_cg_block) {
-			printf("ext2fs: cg %u: block bitmap overlaps gds\n", i);
+			SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
+			    "block bitmap overlaps gds", i);
 			return (EINVAL);
 		}
 		if (b_bitmap < first_block || b_bitmap > last_block) {
-			printf("ext2fs: cg %u: block bitmap not in group, blk=%ju\n",
-			    i, b_bitmap);
+			SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
+			    "block bitmap not in group", i);
 			return (EINVAL);
 		}
 
 		i_bitmap = e2fs_gd_get_i_bitmap(gd);
 		if (i_bitmap == 0) {
-			printf("ext2fs: cg %u: inode bitmap is zero\n", i);
+			SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
+			    "inode bitmap is zero", i);
 			return (EINVAL);
 		}
 		if (i_bitmap <= last_cg_block) {
-			printf("ext2fs: cg %u: inode bitmap overlaps gds\n", i);
+			SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
+			    "inode bitmap overlaps gds", i);
 			return (EINVAL);
 		}
 		if (i_bitmap < first_block || i_bitmap > last_block) {
-			printf("ext2fs: cg %u: inode bitmap not in group blk=%ju\n",
-			    i, i_bitmap);
+			SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
+			    "inode bitmap not in group blk", i);
 			return (EINVAL);
 		}
 
 		i_tables = e2fs_gd_get_i_tables(gd);
 		if (i_tables == 0) {
-			printf("ext2fs: cg %u: inode table is zero\n", i);
+			SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
+			    "inode table is zero", i);
 			return (EINVAL);
 		}
 		if (i_tables <= last_cg_block) {
-			printf("ext2fs: cg %u: inode talbes overlaps gds\n", i);
+			SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
+			    "inode talbes overlaps gds", i);
 			return (EINVAL);
 		}
 		if (i_tables < first_block ||
 		    i_tables + fs->e2fs_itpg - 1 > last_block) {
-			printf("ext2fs: cg %u: inode tables not in group blk=%ju\n",
-			    i, i_tables);
+			SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
+			    "inode tables not in group blk", i);
 			return (EINVAL);
 		}
 
@@ -450,7 +467,8 @@ ext2_compute_sb_data(struct vnode *devvp, struct ext2f
 	/* Check checksum features */
 	if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_GDT_CSUM) &&
 	    EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) {
-		printf("ext2fs: incorrect checksum features combination\n");
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "incorrect checksum features combination");
 		return (EINVAL);
 	}
 
@@ -467,7 +485,8 @@ ext2_compute_sb_data(struct vnode *devvp, struct ext2f
 
 	/* Check for block size = 1K|2K|4K */
 	if (es->e2fs_log_bsize > 2) {
-		printf("ext2fs: bad block size: %d\n", es->e2fs_log_bsize);
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "bad block size");
 		return (EINVAL);
 	}
 
@@ -479,15 +498,15 @@ ext2_compute_sb_data(struct vnode *devvp, struct ext2f
 	/* Check for fragment size */
 	if (es->e2fs_log_fsize >
 	    (EXT2_MAX_FRAG_LOG_SIZE - EXT2_MIN_BLOCK_LOG_SIZE)) {
-		printf("ext2fs: invalid log cluster size: %u\n",
-		    es->e2fs_log_fsize);
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "invalid log cluster size");
 		return (EINVAL);
 	}
 
 	fs->e2fs_fsize = EXT2_MIN_FRAG_SIZE << es->e2fs_log_fsize;
 	if (fs->e2fs_fsize != fs->e2fs_bsize) {
-		printf("ext2fs: fragment size (%u) != block size %u\n",
-		    fs->e2fs_fsize, fs->e2fs_bsize);
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "fragment size != block size");
 		return (EINVAL);
 	}
 
@@ -495,8 +514,8 @@ ext2_compute_sb_data(struct vnode *devvp, struct ext2f
 
 	/* Check reserved gdt blocks for future filesystem expansion */
 	if (es->e2fs_reserved_ngdb > (fs->e2fs_bsize / 4)) {
-		printf("ext2fs: number of reserved GDT blocks too large: %u\n",
-		    es->e2fs_reserved_ngdb);
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "number of reserved GDT blocks too large");
 		return (EINVAL);
 	}
 
@@ -509,8 +528,8 @@ ext2_compute_sb_data(struct vnode *devvp, struct ext2f
 		 * Check first ino.
 		 */
 		if (es->e2fs_first_ino < EXT2_FIRSTINO) {
-			printf("ext2fs: invalid first ino: %u\n",
-			    es->e2fs_first_ino);
+			SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+			    "invalid first ino");
 			return (EINVAL);
 		}
 
@@ -520,8 +539,8 @@ ext2_compute_sb_data(struct vnode *devvp, struct ext2f
 		if (EXT2_INODE_SIZE(fs) < E2FS_REV0_INODE_SIZE ||
 		    EXT2_INODE_SIZE(fs) > fs->e2fs_bsize ||
 		    (fs->e2fs_isize & (fs->e2fs_isize - 1)) != 0) {
-			printf("ext2fs: invalid inode size %u\n",
-			    fs->e2fs_isize);
+			SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+			    "invalid inode size");
 			return (EINVAL);
 		}
 	}
@@ -529,33 +548,36 @@ ext2_compute_sb_data(struct vnode *devvp, struct ext2f
 	/* Check group descriptors */
 	if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_64BIT) &&
 	    es->e3fs_desc_size != E2FS_64BIT_GD_SIZE) {
-			printf("ext2fs: unsupported 64bit descriptor size %u\n",
-			    es->e3fs_desc_size);
-			return (EINVAL);
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "unsupported 64bit descriptor size");
+		return (EINVAL);
 	}
 
 	fs->e2fs_bpg = es->e2fs_bpg;
 	fs->e2fs_fpg = es->e2fs_fpg;
 	if (fs->e2fs_bpg == 0 || fs->e2fs_fpg == 0) {
-		printf("ext2fs: zero blocks/fragments per group\n");
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "zero blocks/fragments per group");
 		return (EINVAL);
 	}
 	if (fs->e2fs_bpg != fs->e2fs_bsize * 8) {
-		printf("ext2fs: non-standard group size unsupported %d\n",
-		    fs->e2fs_bpg);
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "non-standard group size unsupported");
 		return (EINVAL);
 	}
 
 	fs->e2fs_ipb = fs->e2fs_bsize / EXT2_INODE_SIZE(fs);
 	if (fs->e2fs_ipb == 0 ||
 	    fs->e2fs_ipb > fs->e2fs_bsize / E2FS_REV0_INODE_SIZE) {
-		printf("ext2fs: bad inodes per block size\n");
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "bad inodes per block size");
 		return (EINVAL);
 	}
 
 	fs->e2fs_ipg = es->e2fs_ipg;
 	if (fs->e2fs_ipg < fs->e2fs_ipb || fs->e2fs_ipg >  fs->e2fs_bsize * 8) {
-		printf("ext2fs: invalid inodes per group: %u\n", fs->e2fs_ipb);
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "invalid inodes per group");
 		return (EINVAL);
 	}
 
@@ -571,25 +593,29 @@ ext2_compute_sb_data(struct vnode *devvp, struct ext2f
 	}
 	if (fs->e2fs_rbcount > fs->e2fs_bcount ||
 	    fs->e2fs_fbcount > fs->e2fs_bcount) {
-		printf("ext2fs: invalid block count\n");
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "invalid block count");
 		return (EINVAL);
 	}
 	if (es->e2fs_first_dblock >= fs->e2fs_bcount) {
-		printf("ext2fs: first data block out of range\n");
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "first data block out of range");
 		return (EINVAL);
 	}
 
 	fs->e2fs_gcount = howmany(fs->e2fs_bcount - es->e2fs_first_dblock,
 	    EXT2_BLOCKS_PER_GROUP(fs));
 	if (fs->e2fs_gcount > ((uint64_t)1 << 32) - EXT2_DESCS_PER_BLOCK(fs)) {
-		printf("ext2fs: groups count too large: %u\n", fs->e2fs_gcount);
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "groups count too large");
 		return (EINVAL);
 	}
 
 	/* Check for extra isize in big inodes. */
 	if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_EXTRA_ISIZE) &&
 	    EXT2_INODE_SIZE(fs) < sizeof(struct ext2fs_dinode)) {
-		printf("ext2fs: no space for extra inode timestamps\n");
+		SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
+		    "no space for extra inode timestamps");
 		return (EINVAL);
 	}
 
@@ -1095,8 +1121,7 @@ ext2_sync(struct mount *mp, int waitfor)
 	td = curthread;
 	fs = ump->um_e2fs;
 	if (fs->e2fs_fmod != 0 && fs->e2fs_ronly != 0) {		/* XXX */
-		printf("fs = %s\n", fs->e2fs_fsmnt);
-		panic("ext2_sync: rofs mod");
+		panic("ext2_sync: rofs mod fs=%s", fs->e2fs_fsmnt);
 	}
 
 	/*
@@ -1242,7 +1267,7 @@ ext2_vget(struct mount *mp, ino_t ino, int flags, stru
 		for (i = used_blocks; i < EXT2_NDIR_BLOCKS; i++)
 			ip->i_db[i] = 0;
 	}
-#ifdef EXT2FS_DEBUG
+#ifdef EXT2FS_PRINT_EXTENTS
 	ext2_print_inode(ip);
 	ext4_ext_print_extent_tree_status(ip);
 #endif

Modified: head/sys/fs/ext2fs/ext2_vnops.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_vnops.c	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/ext2_vnops.c	Tue Apr 16 11:20:10 2019	(r346267)
@@ -51,6 +51,7 @@
 #include <sys/kernel.h>
 #include <sys/fcntl.h>
 #include <sys/filio.h>
+#include <sys/sdt.h>
 #include <sys/stat.h>
 #include <sys/bio.h>
 #include <sys/buf.h>
@@ -92,6 +93,14 @@
 #include <fs/ext2fs/ext2_extattr.h>
 #include <fs/ext2fs/ext2_extents.h>
 
+SDT_PROVIDER_DECLARE(ext2fs);
+/*
+ * ext2fs trace probe:
+ * arg0: verbosity. Higher numbers give more verbose messages
+ * arg1: Textual message
+ */
+SDT_PROBE_DEFINE2(ext2fs, , vnops, trace, "int", "char*");
+
 static int ext2_makeinode(int mode, struct vnode *, struct vnode **, struct componentname *);
 static void ext2_itimes_locked(struct vnode *);
 
@@ -813,7 +822,8 @@ abortit:
 	 * not call us in that case.  Temporarily just warn if they do.
 	 */
 	if (fvp == tvp) {
-		printf("ext2_rename: fvp == tvp (can't happen)\n");
+		SDT_PROBE2(ext2fs, , vnops, trace, 1,
+		    "rename: fvp == tvp (can't happen)");
 		error = 0;
 		goto abortit;
 	}

Modified: head/sys/fs/ext2fs/fs.h
==============================================================================
--- head/sys/fs/ext2fs/fs.h	Tue Apr 16 09:44:46 2019	(r346266)
+++ head/sys/fs/ext2fs/fs.h	Tue Apr 16 11:20:10 2019	(r346267)
@@ -164,6 +164,6 @@
 /*
  * Use if additional debug logging is required.
  */
-/* #define EXT2FS_DEBUG */
+/* #define EXT2FS_PRINT_EXTENTS */
 
 #endif	/* !_FS_EXT2FS_FS_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904161120.x3GBKBhN036407>