From f38cf3cb34addaa53d1f855d7607b151082a4229 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 1 Sep 2008 11:17:29 -0400 Subject: [PATCH] Only use the test_io manager if the right environment variables are set In order to make it possible for the test_io manager to be compiled in by default, make all of the programs that might try to use it to only do so if the environment variables TEST_IO_FLAGS and TEST_IO_DEBUG are set. Signed-off-by: "Theodore Ts'o" --- e2fsck/unix.c | 9 +++++---- misc/e2image.c | 11 +++++++---- misc/e2initrd_helper.c | 11 +++++++---- misc/mke2fs.c | 18 ++++++++++-------- misc/tune2fs.c | 29 +++++++++++++++++------------ resize/main.c | 7 ++++++- 6 files changed, 52 insertions(+), 33 deletions(-) diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 07549b9..94938a4 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -951,11 +951,12 @@ int main (int argc, char *argv[]) ctx->superblock = ctx->use_superblock; restart: #ifdef CONFIG_TESTIO_DEBUG - io_ptr = test_io_manager; - test_io_backing_manager = unix_io_manager; -#else - io_ptr = unix_io_manager; + if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { + io_ptr = test_io_manager; + test_io_backing_manager = unix_io_manager; + } else #endif + io_ptr = unix_io_manager; flags = EXT2_FLAG_NOFREE_ON_ERROR; if ((ctx->options & E2F_OPT_READONLY) == 0) flags |= EXT2_FLAG_RW; diff --git a/misc/e2image.c b/misc/e2image.c index 9659d49..dd2a1ca 100644 --- a/misc/e2image.c +++ b/misc/e2image.c @@ -23,7 +23,9 @@ extern int optind; #endif #include #include +#ifdef HAVE_STDLIB_H #include +#endif #include #include #include @@ -561,11 +563,12 @@ static void install_image(char *device, char *image_fn, int raw_flag) } #ifdef CONFIG_TESTIO_DEBUG - io_ptr = test_io_manager; - test_io_backing_manager = unix_io_manager; -#else - io_ptr = unix_io_manager; + if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { + io_ptr = test_io_manager; + test_io_backing_manager = unix_io_manager; + } else #endif + io_ptr = unix_io_manager; retval = ext2fs_open (image_fn, open_flag, 0, 0, io_ptr, &fs); diff --git a/misc/e2initrd_helper.c b/misc/e2initrd_helper.c index df09aa1..ca01908 100644 --- a/misc/e2initrd_helper.c +++ b/misc/e2initrd_helper.c @@ -11,7 +11,9 @@ #include #include +#ifdef HAVE_STDLIB_H #include +#endif #include #include #include @@ -370,11 +372,12 @@ int main (int argc, char ** argv) PRS(argc, argv); #ifdef CONFIG_TESTIO_DEBUG - io_ptr = test_io_manager; - test_io_backing_manager = unix_io_manager; -#else - io_ptr = unix_io_manager; + if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { + io_ptr = test_io_manager; + test_io_backing_manager = unix_io_manager; + } else #endif + io_ptr = unix_io_manager; retval = ext2fs_open (device_name, open_flag, 0, 0, io_ptr, &fs); if (retval) exit(1); diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 1dd7e8a..3d830fc 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -1359,11 +1359,12 @@ static void PRS(int argc, char *argv[]) io_manager io_ptr; #ifdef CONFIG_TESTIO_DEBUG - io_ptr = test_io_manager; - test_io_backing_manager = unix_io_manager; -#else - io_ptr = unix_io_manager; + if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { + io_ptr = test_io_manager; + test_io_backing_manager = unix_io_manager; + } else #endif + io_ptr = unix_io_manager; retval = ext2fs_open(journal_device, EXT2_FLAG_JOURNAL_DEV_OK, 0, 0, io_ptr, &jfs); @@ -1839,11 +1840,12 @@ int main (int argc, char *argv[]) PRS(argc, argv); #ifdef CONFIG_TESTIO_DEBUG - io_ptr = test_io_manager; - test_io_backing_manager = unix_io_manager; -#else - io_ptr = unix_io_manager; + if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { + io_ptr = test_io_manager; + test_io_backing_manager = unix_io_manager; + } else #endif + io_ptr = unix_io_manager; if (should_do_undo(device_name)) { retval = mke2fs_setup_tdb(device_name, &io_ptr); diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 5d4cfc0..a130c14 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -37,7 +37,9 @@ extern int optind; #endif #include #include +#ifdef HAVE_STDLIB_H #include +#endif #include #include #include @@ -172,11 +174,12 @@ static void remove_journal_device(ext2_filsys fs) } #ifdef CONFIG_TESTIO_DEBUG - io_ptr = test_io_manager; - test_io_backing_manager = unix_io_manager; -#else - io_ptr = unix_io_manager; + if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { + io_ptr = test_io_manager; + test_io_backing_manager = unix_io_manager; + } else #endif + io_ptr = unix_io_manager; retval = ext2fs_open(journal_path, EXT2_FLAG_RW| EXT2_FLAG_JOURNAL_DEV_OK, 0, fs->blocksize, io_ptr, &jfs); @@ -473,11 +476,12 @@ static void add_journal(ext2_filsys fs) check_plausibility(journal_device); check_mount(journal_device, 0, _("journal")); #ifdef CONFIG_TESTIO_DEBUG - io_ptr = test_io_manager; - test_io_backing_manager = unix_io_manager; -#else - io_ptr = unix_io_manager; + if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { + io_ptr = test_io_manager; + test_io_backing_manager = unix_io_manager; + } else #endif + io_ptr = unix_io_manager; retval = ext2fs_open(journal_device, EXT2_FLAG_RW| EXT2_FLAG_JOURNAL_DEV_OK, 0, fs->blocksize, io_ptr, &jfs); @@ -1436,11 +1440,12 @@ int main (int argc, char ** argv) parse_tune2fs_options(argc, argv); #ifdef CONFIG_TESTIO_DEBUG - io_ptr = test_io_manager; - test_io_backing_manager = unix_io_manager; -#else - io_ptr = unix_io_manager; + if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_DEBUG")) { + io_ptr = test_io_manager; + test_io_backing_manager = unix_io_manager; + } else #endif + io_ptr = unix_io_manager; retry_open: retval = ext2fs_open2(device_name, io_options, open_flag, diff --git a/resize/main.c b/resize/main.c index aeac24b..d6ecd8b 100644 --- a/resize/main.c +++ b/resize/main.c @@ -22,6 +22,9 @@ extern char *optarg; extern int optind; #endif #include +#ifdef HAVE_STDLIB_H +#include +#endif #include #include #include @@ -290,10 +293,12 @@ int main (int argc, char ** argv) fd = -1; } - if (flags & RESIZE_DEBUG_IO) { +#ifdef CONFIG_TESTIO_DEBUG + if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { io_ptr = test_io_manager; test_io_backing_manager = unix_io_manager; } else +#endif io_ptr = unix_io_manager; if (!(mount_flags & EXT2_MF_MOUNTED)) -- 1.8.3.1