fio: factor out fio initialization code
authorStephen M. Cameron <stephenmcameron@gmail.com>
Fri, 24 Feb 2012 07:17:31 +0000 (08:17 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 24 Feb 2012 07:17:31 +0000 (08:17 +0100)
Signed-off-by: Stephen M. Cameron <stephenmcameron@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Makefile
fio.c
fio_initialization.c [new file with mode: 0644]
fio_initialization.h [new file with mode: 0644]

index 434ad70..7607297 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ SOURCE := gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \
                lib/num2str.c lib/ieee754.c $(wildcard crc/*.c) engines/cpu.c \
                engines/mmap.c engines/sync.c engines/null.c engines/net.c \
                memalign.c server.c client.c iolog.c backend.c libfio.c flow.c \
-               endian_check.c
+               endian_check.c fio_initialization.c
 
 ifeq ($(UNAME), Linux)
   SOURCE += diskutil.c fifo.c blktrace.c helpers.c cgroup.c trim.c \
diff --git a/fio.c b/fio.c
index 99d6209..52ed944 100644 (file)
--- a/fio.c
+++ b/fio.c
 #include "memalign.h"
 #include "client.h"
 #include "server.h"
-#include "endian_check.h"
-
-unsigned long page_mask;
-unsigned long page_size;
+#include "fio_initialization.h"
 
 int main(int argc, char *argv[], char *envp[])
 {
-       long ps;
-
-       if (endian_check()) {
-               log_err("fio: endianness settings appear wrong.\n");
-               log_err("fio: please report this to fio@vger.kernel.org\n");
+       if (initialize_fio(envp))
                return 1;
-       }
-
-       arch_init(envp);
-
-       sinit();
-
-       /*
-        * We need locale for number printing, if it isn't set then just
-        * go with the US format.
-        */
-       if (!getenv("LC_NUMERIC"))
-               setlocale(LC_NUMERIC, "en_US");
-
-       ps = sysconf(_SC_PAGESIZE);
-       if (ps < 0) {
-               log_err("Failed to get page size\n");
-               return 1;
-       }
-
-       page_size = ps;
-       page_mask = ps - 1;
-
-       fio_keywords_init();
 
        if (parse_options(argc, argv))
                return 1;
diff --git a/fio_initialization.c b/fio_initialization.c
new file mode 100644 (file)
index 0000000..8bd3374
--- /dev/null
@@ -0,0 +1,43 @@
+#include <locale.h>
+
+#include "endian_check.h"
+#include "smalloc.h"
+#include "fio.h"
+
+
+unsigned long page_mask;
+unsigned long page_size;
+
+int initialize_fio(char *envp[])
+{
+       long ps;
+
+       if (endian_check()) {
+               log_err("fio: endianness settings appear wrong.\n");
+               log_err("fio: please report this to fio@vger.kernel.org\n");
+               return 1;
+       }
+
+       arch_init(envp);
+
+       sinit();
+
+       /*
+        * We need locale for number printing, if it isn't set then just
+        * go with the US format.
+        */
+       if (!getenv("LC_NUMERIC"))
+               setlocale(LC_NUMERIC, "en_US");
+
+       ps = sysconf(_SC_PAGESIZE);
+       if (ps < 0) {
+               log_err("Failed to get page size\n");
+               return 1;
+       }
+
+       page_size = ps;
+       page_mask = ps - 1;
+
+       fio_keywords_init();
+       return 0;
+}
diff --git a/fio_initialization.h b/fio_initialization.h
new file mode 100644 (file)
index 0000000..877cd44
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef FIO_INITIALIZATION
+#define FIO_INITIALIZATION
+
+extern unsigned long page_mask;
+extern unsigned long page_size;
+extern int initialize_fio(char *envp[]);
+
+#endif