solaris: implement blockdev size getting
[fio.git] / os / os-solaris.h
1 #ifndef FIO_OS_SOLARIS_H
2 #define FIO_OS_SOLARIS_H
3
4 #include <errno.h>
5 #include <sys/types.h>
6 #include <sys/fcntl.h>
7 #include <sys/pset.h>
8
9 #define FIO_HAVE_POSIXAIO
10 #define FIO_HAVE_SOLARISAIO
11 #define FIO_HAVE_FALLOCATE
12 #define FIO_HAVE_POSIXAIO_FSYNC
13 #define FIO_HAVE_CPU_AFFINITY
14 #define FIO_HAVE_PSHARED_MUTEX
15
16 #define OS_MAP_ANON             MAP_ANON
17 #define OS_RAND_MAX             2147483648UL
18
19 struct solaris_rand_seed {
20         unsigned short r[3];
21 };
22
23 typedef psetid_t os_cpu_mask_t;
24 typedef struct solaris_rand_seed os_random_state_t;
25
26 /*
27  * FIXME
28  */
29 static inline int blockdev_size(int fd, unsigned long long *bytes)
30 {
31         off_t end = lseek(fd, 0, SEEK_END);
32
33         if (end < 0)
34                 return errno;
35
36         *bytes = end;
37         return 0;
38 }
39
40 static inline int blockdev_invalidate_cache(int fd)
41 {
42         return EINVAL;
43 }
44
45 static inline unsigned long long os_phys_mem(void)
46 {
47         return 0;
48 }
49
50 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
51 {
52         rs->r[0] = seed & 0xffff;
53         seed >>= 16;
54         rs->r[1] = seed & 0xffff;
55         seed >>= 16;
56         rs->r[2] = seed & 0xffff;
57         seed48(rs->r);
58 }
59
60 static inline long os_random_long(os_random_state_t *rs)
61 {
62         return nrand48(rs->r);
63 }
64
65 #define FIO_OS_DIRECTIO
66 extern int directio(int, int);
67 static inline int fio_set_odirect(int fd)
68 {
69         if (directio(fd, DIRECTIO_ON) < 0)
70                 return errno;
71
72         return 0;
73 }
74
75 /*
76  * pset binding hooks for fio
77  */
78 #define fio_setaffinity(pid, cpumask)           \
79         pset_bind((cpumask), P_PID, (pid), NULL)
80 #define fio_getaffinity(pid, ptr)       ({ 0; })
81
82 #define fio_cpu_clear(mask, cpu)        pset_assign(PS_NONE, (cpu), NULL)
83 #define fio_cpu_set(mask, cpu)          pset_assign(*(mask), (cpu), NULL)
84
85 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
86 {
87         int ret;
88
89         if (pset_create(mask) < 0) {
90                 ret = errno;
91                 return -1;
92         }
93
94         return 0;
95 }
96
97 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
98 {
99         int ret;
100
101         if (pset_destroy(*mask) < 0) {
102                 ret = errno;
103                 return -1;
104         }
105
106         return 0;
107 }
108
109 /*
110  * Should be enough, not aware of what (if any) restrictions Solaris has
111  */
112 #define FIO_MAX_CPUS                    16384
113
114 #endif