tests, mke2fs: add option to suppress xattr copying to fix f_extent_htree

If the developer is running with SELinux enabled on /tmp, the
f_extent_htree regression test will fail because mke2fs by default
copies the extended attributes into the newly created file system (if
a directory hierarchy is specified via the -d option).

Fix this by adding a new extended option to mke2fs, -E no_copy_xattrs
and using it in f_extent_htree's test script.

Reported-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index fe859d4..0b04508 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -55,6 +55,7 @@
 ext2_filsys	current_fs;
 quota_ctx_t	current_qctx;
 ext2_ino_t	root, cwd;
+int		no_copy_xattrs;
 
 static int debugfs_setup_tdb(const char *device_name, char *undo_file,
 			     io_manager *io_ptr)
diff --git a/misc/create_inode.c b/misc/create_inode.c
index 6621b0a..05aa636 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -142,6 +142,9 @@
 	char				*list = NULL;
 	int				i;
 
+	if (no_copy_xattrs)
+		return 0;
+
 	size = llistxattr(filename, NULL, 0);
 	if (size == -1) {
 		retval = errno;
diff --git a/misc/create_inode.h b/misc/create_inode.h
index 3a37632..b5eeb42 100644
--- a/misc/create_inode.h
+++ b/misc/create_inode.h
@@ -33,6 +33,9 @@
 		ext2_ino_t parent_ino, ext2_ino_t root, mode_t mode);
 };
 
+extern int no_copy_xattrs; 	/* this should eventually be a flag
+				   passed to populate_fs3() */
+
 /* For populating the filesystem */
 extern errcode_t populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
 			     const char *source_dir, ext2_ino_t root);
diff --git a/misc/mke2fs.8.in b/misc/mke2fs.8.in
index 7b989e0..603e37e 100644
--- a/misc/mke2fs.8.in
+++ b/misc/mke2fs.8.in
@@ -338,6 +338,15 @@
 entirely one time.  If the option value is omitted, it defaults to 1 to
 enable lazy journal inode zeroing.
 .TP
+.BI no_copy_xattrs
+Normally
+.B mke2fs
+will copy the extended attributes of the files in the directory
+hierarchy specified via the (optional)
+.B \-d
+option.  This will disable the copy and leaves the files in the newly
+created file system without any extended attributes.
+.TP
 .BI num_backup_sb= <0|1|2>
 If the
 .B sparse_super2
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index ce78b7c..b23ea76 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -95,6 +95,7 @@
 int	journal_flags;
 static int	lazy_itable_init;
 static int	packed_meta_blocks;
+int		no_copy_xattrs;
 static char	*bad_blocks_filename = NULL;
 static __u32	fs_stride;
 /* Initialize usr/grp quotas by default */
@@ -880,6 +881,9 @@
 				r_usage++;
 				continue;
 			}
+		} else if (strcmp(token, "no_copy_xattrs") == 0) {
+			no_copy_xattrs = 1;
+			continue;
 		} else if (strcmp(token, "num_backup_sb") == 0) {
 			if (!arg) {
 				r_usage++;
diff --git a/tests/f_extent_htree/script b/tests/f_extent_htree/script
index ccd97e1..4939acc 100644
--- a/tests/f_extent_htree/script
+++ b/tests/f_extent_htree/script
@@ -30,8 +30,8 @@
 # make filesystem with enough inodes and blocks to hold all the test files
 > $TMPFILE
 NUM=$((NUM * 5 / 3))
-echo "mke2fs -b $BSIZE -O dir_index,extent -d$SRC -N$NUM $TMPFILE $NUM" >> $OUT
-$MKE2FS -b $BSIZE -O dir_index,extent -d$SRC -N$NUM $TMPFILE $NUM >> $OUT 2>&1
+echo "mke2fs -b $BSIZE -O dir_index,extent -E no_copy_xattrs -d$SRC -N$NUM $TMPFILE $NUM" >> $OUT
+$MKE2FS -b $BSIZE -O dir_index,extent -E no_copy_xattrs -d$SRC -N$NUM $TMPFILE $NUM >> $OUT 2>&1
 rm -r $SRC
 
 # Run e2fsck to convert dir to htree before deleting the files, as mke2fs