Add support for compiling for ESX
authorJens Axboe <axboe@fb.com>
Wed, 18 Jun 2014 22:30:09 +0000 (15:30 -0700)
committerJens Axboe <axboe@fb.com>
Wed, 18 Jun 2014 22:30:09 +0000 (15:30 -0700)
With contributions from Ryan Haynes <rhaynes@fusionio.com>

Signed-off-by: Jens Axboe <axboe@fb.com>
README
backend.c
configure
filesetup.c
init.c
options.c
parse.c
parse.h
smalloc.c

diff --git a/README b/README
index f8aaef275a916dc7e1fe1233dd3fbf888c72f5eb..2be0bfd2031d926a6291f94b76f8378e5d8d67db 100644 (file)
--- a/README
+++ b/README
@@ -101,6 +101,9 @@ To build FIO with a cross-compiler:
  $ make CROSS_COMPILE=/path/to/toolchain/prefix
 Configure will attempt to determine the target platform automatically.
 
  $ make CROSS_COMPILE=/path/to/toolchain/prefix
 Configure will attempt to determine the target platform automatically.
 
+It's possible to build fio for ESX as well, use the --esx switch to
+configure.
+
 
 Windows
 -------
 
 Windows
 -------
index 23fa345b7e19496ae64af4a0bfa8983ddaefe794..ee75566af84cd6f07a8a4e824ba79e9788667d1b 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1575,7 +1575,7 @@ static int fork_main(int shmid, int offset)
        struct thread_data *td;
        void *data, *ret;
 
        struct thread_data *td;
        void *data, *ret;
 
-#ifndef __hpux
+#if !defined(__hpux) && !defined(CONFIG_NO_SHM)
        data = shmat(shmid, NULL, 0);
        if (data == (void *) -1) {
                int __err = errno;
        data = shmat(shmid, NULL, 0);
        if (data == (void *) -1) {
                int __err = errno;
index d37e8b4bd505de82835702a21c39d0b0ea75349b..0e861eef906bdb12f3a4099522e5c7ae35a50484 100755 (executable)
--- a/configure
+++ b/configure
@@ -141,6 +141,10 @@ for opt do
   case "$opt" in
   --cpu=*) cpu="$optarg"
   ;;
   case "$opt" in
   --cpu=*) cpu="$optarg"
   ;;
+  #  esx is cross compiled and cannot be detect through simple uname calls
+  --esx)
+  esx="yes"
+  ;;
   --cc=*) CC="$optarg"
   ;;
   --extra-cflags=*) CFLAGS="$CFLAGS $optarg"
   --cc=*) CC="$optarg"
   ;;
   --extra-cflags=*) CFLAGS="$CFLAGS $optarg"
@@ -167,6 +171,7 @@ if test "$show_help" = "yes" ; then
   echo "--cc=                  Specify compiler to use"
   echo "--extra-cflags=        Specify extra CFLAGS to pass to compiler"
   echo "--build-32bit-win      Enable 32-bit build on Windows"
   echo "--cc=                  Specify compiler to use"
   echo "--extra-cflags=        Specify extra CFLAGS to pass to compiler"
   echo "--build-32bit-win      Enable 32-bit build on Windows"
+  echo "--esx                  Configure build options for esx"
   echo "--enable-gfio          Enable building of gtk gfio"
   echo "--disable-numa         Disable libnuma even if found"
   exit $exit_val
   echo "--enable-gfio          Enable building of gtk gfio"
   echo "--disable-numa         Disable libnuma even if found"
   exit $exit_val
@@ -1340,6 +1345,10 @@ fi
 if test "$gfio" = "yes" ; then
   echo "CONFIG_GFIO=y" >> $config_host_mak
 fi
 if test "$gfio" = "yes" ; then
   echo "CONFIG_GFIO=y" >> $config_host_mak
 fi
+if test "$esx" = "yes" ; then
+  output_sym "CONFIG_ESX"
+  output_sym "CONFIG_NO_SHM"
+fi
 if test "$sched_idle" = "yes" ; then
   output_sym "CONFIG_SCHED_IDLE"
 fi
 if test "$sched_idle" = "yes" ; then
   output_sym "CONFIG_SCHED_IDLE"
 fi
index 2049fd6502cc80ec8c0214c55029c5cad7fb1786..1facccd79f995021c03b80dead4a103b067c9189 100644 (file)
@@ -390,6 +390,10 @@ static int __file_invalidate_cache(struct thread_data *td, struct fio_file *f,
 {
        int ret = 0;
 
 {
        int ret = 0;
 
+#ifdef CONFIG_ESX
+       return 0;
+#endif
+
        if (len == -1ULL)
                len = f->io_size;
        if (off == -1ULL)
        if (len == -1ULL)
                len = f->io_size;
        if (off == -1ULL)
diff --git a/init.c b/init.c
index 74a02e07422f37477f8b3a883c0f02ffa6a22bd1..d44eb5b1eaa2fb086afe25b3a6bda335320decf7 100644 (file)
--- a/init.c
+++ b/init.c
@@ -238,15 +238,19 @@ static struct option l_opts[FIO_NR_OPTIONS] = {
 
 void free_threads_shm(void)
 {
 
 void free_threads_shm(void)
 {
-       struct shmid_ds sbuf;
-
        if (threads) {
                void *tp = threads;
        if (threads) {
                void *tp = threads;
+#ifndef CONFIG_NO_SHM
+               struct shmid_ds sbuf;
 
                threads = NULL;
                shmdt(tp);
                shmctl(shm_id, IPC_RMID, &sbuf);
                shm_id = -1;
 
                threads = NULL;
                shmdt(tp);
                shmctl(shm_id, IPC_RMID, &sbuf);
                shm_id = -1;
+#else
+               threads = NULL;
+               free(tp);
+#endif
        }
 }
 
        }
 }
 
@@ -287,6 +291,7 @@ static int setup_thread_area(void)
                size += file_hash_size;
                size += sizeof(unsigned int);
 
                size += file_hash_size;
                size += sizeof(unsigned int);
 
+#ifndef CONFIG_NO_SHM
                shm_id = shmget(0, size, IPC_CREAT | 0600);
                if (shm_id != -1)
                        break;
                shm_id = shmget(0, size, IPC_CREAT | 0600);
                if (shm_id != -1)
                        break;
@@ -294,10 +299,16 @@ static int setup_thread_area(void)
                        perror("shmget");
                        break;
                }
                        perror("shmget");
                        break;
                }
+#else
+               threads = malloc(size);
+               if (threads)
+                       break;
+#endif
 
                max_jobs >>= 1;
        } while (max_jobs);
 
 
                max_jobs >>= 1;
        } while (max_jobs);
 
+#ifndef CONFIG_NO_SHM
        if (shm_id == -1)
                return 1;
 
        if (shm_id == -1)
                return 1;
 
@@ -306,6 +317,7 @@ static int setup_thread_area(void)
                perror("shmat");
                return 1;
        }
                perror("shmat");
                return 1;
        }
+#endif
 
        memset(threads, 0, max_jobs * sizeof(struct thread_data));
        hash = (void *) threads + max_jobs * sizeof(struct thread_data);
 
        memset(threads, 0, max_jobs * sizeof(struct thread_data));
        hash = (void *) threads + max_jobs * sizeof(struct thread_data);
@@ -1947,6 +1959,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        break;
                case 'S':
                        did_arg = 1;
                        break;
                case 'S':
                        did_arg = 1;
+#ifndef CONFIG_NO_SHM
                        if (nr_clients) {
                                log_err("fio: can't be both client and server\n");
                                do_exit++;
                        if (nr_clients) {
                                log_err("fio: can't be both client and server\n");
                                do_exit++;
@@ -1957,6 +1970,11 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                                fio_server_set_arg(optarg);
                        is_backend = 1;
                        backend = 1;
                                fio_server_set_arg(optarg);
                        is_backend = 1;
                        backend = 1;
+#else
+                       log_err("fio: client/server requires SHM support\n");
+                       do_exit++;
+                       exit_val = 1;
+#endif
                        break;
                case 'D':
                        if (pid_file)
                        break;
                case 'D':
                        if (pid_file)
index d5bf00c38fbbccd00b394f1219bb0d0b63d84f6f..74347f3554e02b027d42f8012ebe96cbb9cbc716 100644 (file)
--- a/options.c
+++ b/options.c
@@ -2226,6 +2226,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                            .oval = MEM_MALLOC,
                            .help = "Use malloc(3) for IO buffers",
                          },
                            .oval = MEM_MALLOC,
                            .help = "Use malloc(3) for IO buffers",
                          },
+#ifndef CONFIG_NO_SHM
                          { .ival = "shm",
                            .oval = MEM_SHM,
                            .help = "Use shared memory segments for IO buffers",
                          { .ival = "shm",
                            .oval = MEM_SHM,
                            .help = "Use shared memory segments for IO buffers",
@@ -2235,6 +2236,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                            .oval = MEM_SHMHUGE,
                            .help = "Like shm, but use huge pages",
                          },
                            .oval = MEM_SHMHUGE,
                            .help = "Like shm, but use huge pages",
                          },
+#endif
 #endif
                          { .ival = "mmap",
                            .oval = MEM_MMAP,
 #endif
                          { .ival = "mmap",
                            .oval = MEM_MMAP,
@@ -3048,6 +3050,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .type   = FIO_OPT_STR_SET,
                .off1   = td_var_offset(use_thread),
                .help   = "Use threads instead of processes",
                .type   = FIO_OPT_STR_SET,
                .off1   = td_var_offset(use_thread),
                .help   = "Use threads instead of processes",
+#ifdef CONFIG_NO_SHM
+               .def    = "1",
+               .no_warn_def = 1,
+#endif
                .category = FIO_OPT_C_GENERAL,
                .group  = FIO_OPT_G_PROCESS,
        },
                .category = FIO_OPT_C_GENERAL,
                .group  = FIO_OPT_G_PROCESS,
        },
diff --git a/parse.c b/parse.c
index 188f72826185d2a1c3dba8f48bca01ccfa2a1e56..e6d9406e1612231a295516eab1bde32e72bd8a37 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -1167,7 +1167,7 @@ void option_init(struct fio_option *o)
                o->minfp = DBL_MIN;
                o->maxfp = DBL_MAX;
        }
                o->minfp = DBL_MIN;
                o->maxfp = DBL_MAX;
        }
-       if (o->type == FIO_OPT_STR_SET && o->def) {
+       if (o->type == FIO_OPT_STR_SET && o->def && !o->no_warn_def) {
                log_err("Option %s: string set option with"
                                " default will always be true\n", o->name);
        }
                log_err("Option %s: string set option with"
                                " default will always be true\n", o->name);
        }
diff --git a/parse.h b/parse.h
index c797b925bdc5066b9d570303055ccffb58dc7b53..2a1e06a45c540f2e29354a94ad52f8b026194473 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -73,6 +73,7 @@ struct fio_option {
        unsigned int group;             /* who to group with */
        void *gui_data;
        int is_seconds;                 /* time value with seconds base */
        unsigned int group;             /* who to group with */
        void *gui_data;
        int is_seconds;                 /* time value with seconds base */
+       int no_warn_def;
 };
 
 typedef int (str_cb_fn)(void *, char *);
 };
 
 typedef int (str_cb_fn)(void *, char *);
index c8f1642eb54cfc7863182286be03d03599dd4dae..d0f732baee6cc6515e26f554432fae87958c0bf6 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -180,6 +180,7 @@ static int find_next_zero(int word, int start)
 static int add_pool(struct pool *pool, unsigned int alloc_size)
 {
        int bitmap_blocks;
 static int add_pool(struct pool *pool, unsigned int alloc_size)
 {
        int bitmap_blocks;
+       int mmap_flags;
        void *ptr;
 
 #ifdef SMALLOC_REDZONE
        void *ptr;
 
 #ifdef SMALLOC_REDZONE
@@ -198,8 +199,14 @@ static int add_pool(struct pool *pool, unsigned int alloc_size)
        pool->nr_blocks = bitmap_blocks;
        pool->free_blocks = bitmap_blocks * SMALLOC_BPB;
 
        pool->nr_blocks = bitmap_blocks;
        pool->free_blocks = bitmap_blocks * SMALLOC_BPB;
 
-       ptr = mmap(NULL, alloc_size, PROT_READ|PROT_WRITE,
-                       MAP_SHARED | OS_MAP_ANON, -1, 0);
+       mmap_flags = OS_MAP_ANON;
+#ifdef CONFIG_ESX
+       mmap_flags |= MAP_PRIVATE;
+#else
+       mmap_flags |= MAP_SHARED;
+#endif
+       ptr = mmap(NULL, alloc_size, PROT_READ|PROT_WRITE, mmap_flags, -1, 0);
+
        if (ptr == MAP_FAILED)
                goto out_fail;
 
        if (ptr == MAP_FAILED)
                goto out_fail;