Make it work on opensolaris
authorJens Axboe <jens.axboe@oracle.com>
Fri, 30 May 2008 13:02:38 +0000 (15:02 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 30 May 2008 13:02:38 +0000 (15:02 +0200)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
21 files changed:
Makefile.solaris
arch/arch.h
crc/sha256.c
crc/sha512.c
debug.h
engines/mmap.c
engines/net.c
engines/sync.c
filesetup.c
fio.c
fio.h
hash.h
init.c
log.c
memory.c
mutex.c
options.c
os/os-linux.h
os/os.h
stat.c
verify.c

index 2f088b5f07fc732007b83c40500f3ea545456e63..fbdef12c45f3944fb869005a67b6b959efcb2faa 100644 (file)
@@ -1,5 +1,5 @@
 CC     = gcc
-CFLAGS = -Wall -O2 -g -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
+CFLAGS = -Wall -O2 -g -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DFIO_INC_DEBUG
 PROGS  = fio
 SCRIPTS = fio_generate_plots
 OBJS = gettime.o fio.o ioengines.o init.o stat.o log.o time.o filesetup.o \
@@ -21,24 +21,26 @@ OBJS += engines/sync.o
 OBJS += engines/null.o
 OBJS += engines/net.o
 
-all: depend $(PROGS) $(SCRIPTS)
+OBJS += lib/strsep.o
 
+INSTALL = install
+prefix = /usr/local
+bindir = $(prefix)/bin
+mandir = $(prefix)/man
+
+%.o: %.c
+       $(CC) -o $*.o -c $(CFLAGS) $<
 fio: $(OBJS)
-       $(CC) $(CFLAGS) -o $@ $(OBJS) -lc -lpthread -lm -laio -lrt -ldl
+       $(CC) $(CFLAGS) -o $@ $(OBJS) $(EXTLIBS) -lpthread -lm -ldl -laio -lrt -lnsl -lsocket
 
-clean:
-       -rm -f *.o .depend cscope.out $(PROGS)
+all: $(PROGS) $(SCRIPTS)
 
-depend:
-       @$(CC) -MM $(ALL_CFLAGS) *.c engines/*.c 1> .depend
+clean:
+       -rm -f *.o .depend cscope.out $(PROGS) engines/*.o crc/*.o lib/*.o core.* core
 
 cscope:
        @cscope -b
 
-INSTALL = install
-prefix = /usr/local
-bindir = $(prefix)/bin
-
 install: $(PROGS) $(SCRIPTS)
        $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
        $(INSTALL) $(PROGS) $(SCRIPTS) $(DESTDIR)$(bindir)
index 745bf3a4d0a6260dffc37b475e3b3479e966ba48..3962c9291bebf1abe4babee787f253198a913e98 100644 (file)
@@ -37,6 +37,4 @@ static inline unsigned long generic_ffz(unsigned long word)
 #error "Unsupported arch"
 #endif
 
-#define BITS_PER_LONG  (__WORDSIZE)
-
 #endif
index 8ec2943294e48ac2a3e9e22892a0723fa05b4f8e..fe08ab3a0e0554ed417e6b7c11dedadffd20677b 100644 (file)
  */
 #include <string.h>
 #include <inttypes.h>
-#include <byteswap.h>
-#include <endian.h>
 
 #include "sha256.h"
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
-#define        __be32_to_cpu(x)        __bswap_32(x)
+static int __be32_to_cpu(uint32_t val)
+{
+       uint32_t c1, c2, c3, c4;
+
+       c1 = (val >> 24) & 0xff;
+       c2 = (val >> 16) & 0xff;
+       c3 = (val >> 8) & 0xff;
+       c4 = val & 0xff;
+
+       return c1 | c2 << 8 | c3 << 16 | c4 << 24;
+}
 #else
 #define __be32_to_cpu(x)       (x)
 #endif
index 1f9ebb434baf2707f909d33c63b48ae84ed06a64..d9069e30d6cdeea90e63d0800d7532ff49617bd7 100644 (file)
 
 #include <string.h>
 #include <inttypes.h>
-#include <byteswap.h>
-#include <endian.h>
 
 #include "sha512.h"
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
-#define        __be64_to_cpu(x)        __bswap_64(x)
+static int __be64_to_cpu(uint64_t val)
+{
+       uint64_t c1, c2, c3, c4, c5, c6, c7, c8;
+
+       c1 = (val >> 56) & 0xff;
+       c2 = (val >> 48) & 0xff;
+       c3 = (val >> 40) & 0xff;
+       c4 = (val >> 32) & 0xff;
+       c5 = (val >> 24) & 0xff;
+       c6 = (val >> 16) & 0xff;
+       c7 = (val >> 8) & 0xff;
+       c8 = val & 0xff;
+
+       return c1 | c2 << 8 | c3 << 16 | c4 << 24 | c5 << 32 | c6 << 40 | c7 << 48 | c8 << 56;
+}
 #else
 #define __be64_to_cpu(x)       (x)
 #endif
diff --git a/debug.h b/debug.h
index 883628da0b22fb07c9838ce0aa63b90f9e355576..160f48c3b75a9bcfc62eb0ce614181f5daa5a088 100644 (file)
--- a/debug.h
+++ b/debug.h
@@ -39,7 +39,7 @@ extern unsigned int fio_debug_jobno, *fio_debug_jobp;
                    && pid != *fio_debug_jobp)                  \
                        break;                                  \
                log_info("%-8s ", debug_levels[(type)].name);   \
-               log_info("%-5u ", pid);                         \
+               log_info("%-5u ", (int) pid);                   \
                log_info(str, ##args);                          \
        } while (0)
 
index 3e1e6c8d9a38c5e4536cb34985680f6e6c9694cb..5b55a811511d594cc5f84c86e828da7a6157c800 100644 (file)
@@ -9,7 +9,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
-#include <assert.h>
 #include <sys/mman.h>
 
 #include "../fio.h"
index 137c5799169fa10fbdbaeb597c87f0c7c17f0b95..0efd3369ab3ae6b9caf4f327682a9d30ffcb71bd 100644 (file)
@@ -41,6 +41,7 @@ static int fio_netio_prep(struct thread_data *td, struct io_u *io_u)
        return 0;
 }
 
+#ifdef FIO_HAVE_SPLICE
 static int splice_io_u(int fdin, int fdout, unsigned int len)
 {
        int bytes = 0;
@@ -161,6 +162,19 @@ static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u)
 
        return ret;
 }
+#else
+static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u)
+{
+       errno = -EOPNOTSUPP;
+       return -1;
+}
+
+static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u)
+{
+       errno = -EOPNOTSUPP;
+       return -1;
+}
+#endif
 
 static int fio_netio_send(struct thread_data *td, struct io_u *io_u)
 {
@@ -169,8 +183,10 @@ static int fio_netio_send(struct thread_data *td, struct io_u *io_u)
        /*
         * if we are going to write more, set MSG_MORE
         */
+#ifdef MSG_MORE
        if (td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen < td->o.size)
                flags = MSG_MORE;
+#endif
 
        return send(io_u->file->fd, io_u->xfer_buf, io_u->xfer_buflen, flags);
 }
@@ -430,6 +446,7 @@ static int fio_netio_setup(struct thread_data *td)
        return 0;
 }
 
+#ifdef FIO_HAVE_SPLICE
 static int fio_netio_setup_splice(struct thread_data *td)
 {
        struct netio_data *nd;
@@ -448,12 +465,12 @@ static int fio_netio_setup_splice(struct thread_data *td)
        return 1;
 }
 
-static struct ioengine_ops ioengine_rw = {
-       .name           = "net",
+static struct ioengine_ops ioengine_splice = {
+       .name           = "netsplice",
        .version        = FIO_IOOPS_VERSION,
        .prep           = fio_netio_prep,
        .queue          = fio_netio_queue,
-       .setup          = fio_netio_setup,
+       .setup          = fio_netio_setup_splice,
        .init           = fio_netio_init,
        .cleanup        = fio_netio_cleanup,
        .open_file      = fio_netio_open_file,
@@ -461,13 +478,14 @@ static struct ioengine_ops ioengine_rw = {
        .flags          = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
                          FIO_SIGQUIT,
 };
+#endif
 
-static struct ioengine_ops ioengine_splice = {
-       .name           = "netsplice",
+static struct ioengine_ops ioengine_rw = {
+       .name           = "net",
        .version        = FIO_IOOPS_VERSION,
        .prep           = fio_netio_prep,
        .queue          = fio_netio_queue,
-       .setup          = fio_netio_setup_splice,
+       .setup          = fio_netio_setup,
        .init           = fio_netio_init,
        .cleanup        = fio_netio_cleanup,
        .open_file      = fio_netio_open_file,
@@ -479,11 +497,15 @@ static struct ioengine_ops ioengine_splice = {
 static void fio_init fio_netio_register(void)
 {
        register_ioengine(&ioengine_rw);
+#ifdef FIO_HAVE_SPLICE
        register_ioengine(&ioengine_splice);
+#endif
 }
 
 static void fio_exit fio_netio_unregister(void)
 {
        unregister_ioengine(&ioengine_rw);
+#ifdef FIO_HAVE_SPLICE
        unregister_ioengine(&ioengine_splice);
+#endif
 }
index e966846cd34c3d560b3c03e2177e42d1a65cb0dc..561e77ba02539e7ca88e5a70ea141a01c0a66529 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <sys/uio.h>
 #include <errno.h>
 #include <assert.h>
 
index c98bf0c0ac934c0939529c2664c8c82844ce3896..d57a3277563c3a45c13943dcc00da0d501e03a22 100644 (file)
@@ -307,7 +307,7 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
        if (td->o.sync_io)
                flags |= O_SYNC;
        if (f->filetype != FIO_TYPE_FILE)
-               flags |= O_NOATIME;
+               flags |= FIO_O_NOATIME;
 
 open_again:
        if (td_write(td)) {
@@ -337,8 +337,8 @@ open_again:
                char buf[FIO_VERROR_SIZE];
                int __e = errno;
 
-               if (errno == EPERM && (flags & O_NOATIME)) {
-                       flags &= ~O_NOATIME;
+               if (errno == EPERM && (flags & FIO_O_NOATIME)) {
+                       flags &= ~FIO_O_NOATIME;
                        goto open_again;
                }
 
diff --git a/fio.c b/fio.c
index 37a425e85ee6fde71ec7aa537b0f6947687cc128..c5926289b34475bd511e8b8b5fadb0ce44b50c06 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -65,8 +65,8 @@ static inline void td_set_runstate(struct thread_data *td, int runstate)
        if (td->runstate == runstate)
                return;
 
-       dprint(FD_PROCESS, "pid=%d: runstate %d -> %d\n", td->pid, td->runstate,
-                                                               runstate);
+       dprint(FD_PROCESS, "pid=%d: runstate %d -> %d\n", (int) td->pid,
+                                               td->runstate, runstate);
        td->runstate = runstate;
 }
 
@@ -80,7 +80,7 @@ static void terminate_threads(int group_id)
        for_each_td(td, i) {
                if (group_id == TERMINATE_ALL || groupid == td->groupid) {
                        dprint(FD_PROCESS, "setting terminate on %s/%d\n",
-                                                       td->o.name, td->pid);
+                                               td->o.name, (int) td->pid);
                        td->terminate = 1;
                        td->o.start_delay = 0;
 
@@ -823,7 +823,7 @@ static void *thread_main(void *data)
 
        td->pid = getpid();
 
-       dprint(FD_PROCESS, "jobs pid=%d started\n", td->pid);
+       dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
 
        INIT_LIST_HEAD(&td->io_u_freelist);
        INIT_LIST_HEAD(&td->io_u_busylist);
@@ -975,7 +975,7 @@ static void *thread_main(void *data)
 
 err:
        if (td->error)
-               printf("fio: pid=%d, err=%d/%s\n", td->pid, td->error,
+               printf("fio: pid=%d, err=%d/%s\n", (int) td->pid, td->error,
                                                        td->verror);
        close_and_free_files(td);
        close_ioengine(td);
@@ -1063,8 +1063,8 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
                ret = waitpid(td->pid, &status, flags);
                if (ret < 0) {
                        if (errno == ECHILD) {
-                               log_err("fio: pid=%d disappeared %d\n", td->pid,
-                                                               td->runstate);
+                               log_err("fio: pid=%d disappeared %d\n",
+                                               (int) td->pid, td->runstate);
                                td_set_runstate(td, TD_REAPED);
                                goto reaped;
                        }
@@ -1075,7 +1075,7 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
 
                                if (sig != SIGQUIT)
                                        log_err("fio: pid=%d, got signal=%d\n",
-                                                               td->pid, sig);
+                                                       (int) td->pid, sig);
                                td_set_runstate(td, TD_REAPED);
                                goto reaped;
                        }
@@ -1161,8 +1161,8 @@ static void run_threads(void)
                if (setup_files(td)) {
                        exit_value++;
                        if (td->error)
-                               log_err("fio: pid=%d, err=%d/%s\n", td->pid,
-                                                       td->error, td->verror);
+                               log_err("fio: pid=%d, err=%d/%s\n",
+                                       (int) td->pid, td->error, td->verror);
                        td_set_runstate(td, TD_REAPED);
                        todo--;
                } else {
diff --git a/fio.h b/fio.h
index 472fe9370c69f4c23907ac3af698da79c5da26cd..b8847a5cbb3d39553b3fa6492c6bdf6a90dd0bed 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -1006,7 +1006,8 @@ static inline void dprint_io_u(struct io_u *io_u, const char *p)
        struct fio_file *f = io_u->file;
 
        dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
-                                       io_u->offset, io_u->buflen, io_u->ddir);
+                                       (unsigned long long) io_u->offset,
+                                       io_u->buflen, io_u->ddir);
        if (fio_debug & (1 << FD_IO)) {
                if (f)
                        log_info("/%s", f->file_name);
diff --git a/hash.h b/hash.h
index acf17bb8e7f963b1ea5400a17d24819f319a8062..3e7854b12615e354ca4e518443833d187f0d91b1 100644 (file)
--- a/hash.h
+++ b/hash.h
  * them can use shifts and additions instead of multiplications for
  * machines where multiplications are slow.
  */
+
+#ifdef __WORDSIZE
+#define BITS_PER_LONG  __WORDSIZE
+#else
+#define BITS_PER_LONG  32
+#endif
+
 #if BITS_PER_LONG == 32
 /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
 #define GOLDEN_RATIO_PRIME 0x9e370001UL
diff --git a/init.c b/init.c
index 56a1d331625ae6804bb92540a36551bd4a855d34..00eb592bef7fadddc1314a77658b26c2637475de 100644 (file)
--- a/init.c
+++ b/init.c
@@ -307,7 +307,7 @@ static int fixup_options(struct thread_data *td)
        }
 
        if (o->fill_device && !o->size)
-               o->size = ULONG_LONG_MAX;
+               o->size = -1ULL;
 
        if (td_rw(td) && td->o.verify != VERIFY_NONE)
                log_info("fio: mixed read/write workload with verify. May not "
diff --git a/log.c b/log.c
index 8f92e93f065d7b57234bbdbccf8bab875f785fe9..191f806aa2e471747f8c561ba59365c4f2269ad9 100644 (file)
--- a/log.c
+++ b/log.c
@@ -4,6 +4,7 @@
  */
 #include <stdio.h>
 #include <stdlib.h>
+#include <libgen.h>
 #include <assert.h>
 #include "list.h"
 #include "fio.h"
index 257914b153a1f37469b3e42071a78a601901f5cc..3bf31d76104ec0be8e63eeb80c8ed35cbb816571 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -1,6 +1,9 @@
 /*
  * Memory helpers
  */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <unistd.h>
 #include <sys/shm.h>
 #include <sys/mman.h>
diff --git a/mutex.c b/mutex.c
index e6fb3f0d01b96f82dd789de5201362fed3ed9433..414e5532d1385f3b9ceda3b6e316907b5a978376 100644 (file)
--- a/mutex.c
+++ b/mutex.c
@@ -12,7 +12,7 @@
 void fio_mutex_remove(struct fio_mutex *mutex)
 {
        close(mutex->mutex_fd);
-       munmap(mutex, sizeof(*mutex));
+       munmap((void *) mutex, sizeof(*mutex));
 }
 
 struct fio_mutex *fio_mutex_init(int value)
@@ -34,8 +34,8 @@ struct fio_mutex *fio_mutex_init(int value)
                goto err;
        }
 
-       mutex = mmap(NULL, sizeof(struct fio_mutex), PROT_READ | PROT_WRITE,
-                       MAP_SHARED, fd, 0);
+       mutex = (void *) mmap(NULL, sizeof(struct fio_mutex),
+                               PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
        if (mutex == MAP_FAILED) {
                perror("mmap mutex");
                close(fd);
index b8df1da1f90756f68cd5fd15b50500b646ba55b3..5aad00501c42b124cf9a7198c45aba5769c9baa2 100644 (file)
--- a/options.c
+++ b/options.c
@@ -6,6 +6,9 @@
 #include <getopt.h>
 #include <assert.h>
 #include <libgen.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include "fio.h"
 #include "parse.h"
@@ -1275,7 +1278,7 @@ void fio_options_dup_and_init(struct option *long_options)
 
        o = &options[0];
        while (o->name) {
-               long_options[i].name = o->name;
+               long_options[i].name = (char *) o->name;
                long_options[i].val = FIO_GETOPT_JOB;
                if (o->type == FIO_OPT_STR_SET)
                        long_options[i].has_arg = no_argument;
index e7c0e47cbf0e5c23bbbe8feb0722b97d49a3ded0..6f2372bcd7e48bc7074928a4afa0212202ebade3 100644 (file)
@@ -25,6 +25,7 @@
 #define FIO_HAVE_HUGETLB
 #define FIO_HAVE_RAWBIND
 #define FIO_HAVE_BLKTRACE
+#define FIO_HAVE_STRSEP
 
 #define OS_MAP_ANON            (MAP_ANONYMOUS)
 
@@ -227,4 +228,6 @@ static inline int fio_lookup_raw(dev_t dev, int *majdev, int *mindev)
        return 0;
 }
 
+#define FIO_O_NOATIME  O_NOATIME
+
 #endif
diff --git a/os/os.h b/os/os.h
index 42cd63d020aedf28e91114ef171697e4f393b6e1..b1ed1bb6953dfc563904a7f4f13496a0c669b87a 100644 (file)
--- a/os/os.h
+++ b/os/os.h
 #include <scsi/sg.h>
 #endif
 
+#ifndef FIO_HAVE_STRSEP
+#include "../lib/lib.h"
+#endif
+
 #ifndef FIO_HAVE_FADVISE
 #define fadvise(fd, off, len, advice)  (0)
 
@@ -36,7 +40,7 @@
 
 #ifndef FIO_HAVE_CPU_AFFINITY
 #define fio_setaffinity(td)            (0)
-#define fio_getaffinity(pid, mask)     (0)
+#define fio_getaffinity(pid, mask)     do { } while(0)
 #endif
 
 #ifndef FIO_HAVE_IOPRIO
 #endif
 #endif
 
+#ifndef FIO_O_NOATIME
+#define FIO_O_NOATIME                  0
+#endif
+
 #ifndef FIO_HAVE_RAWBIND
 #define fio_lookup_raw(dev, majdev, mindev)    1
 #endif
@@ -69,6 +77,7 @@ static inline int is_blktrace(const char *fname)
 {
        return 0;
 }
+struct thread_data;
 static inline int load_blktrace(struct thread_data *td, const char *fname)
 {
        return 1;
diff --git a/stat.c b/stat.c
index fe6acb804c2f320f728128fed6e124c599644dd2..5fecbd043e088fc1b9d12983e143ebf7a338c481 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -320,11 +320,11 @@ static void show_thread_status(struct thread_stat *ts,
        if (!ts->error) {
                log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n",
                                        ts->name, ts->groupid, ts->members,
-                                       ts->error, ts->pid);
+                                       ts->error, (int) ts->pid);
        } else {
                log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n",
                                        ts->name, ts->groupid, ts->members,
-                                       ts->error, ts->verror, ts->pid);
+                                       ts->error, ts->verror, (int) ts->pid);
        }
 
        if (ts->description)
index 0bb348ff996995750cc797eca653f5567160e980..d602534893319df149aa5355106e244df60730b2 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -112,7 +112,7 @@ static void hexdump(void *buffer, int len)
  */
 static inline unsigned int __hdr_size(int verify_type)
 {
-       unsigned int len;
+       unsigned int len = len;
 
        switch (verify_type) {
        case VERIFY_NONE: