… | |
… | |
71 | #endif |
71 | #endif |
72 | #ifndef ELOOP |
72 | #ifndef ELOOP |
73 | # define ELOOP EDOM |
73 | # define ELOOP EDOM |
74 | #endif |
74 | #endif |
75 | |
75 | |
|
|
76 | #if !defined(ENOTSOCK) && defined(WSAENOTSOCK) |
|
|
77 | # define ENOTSOCK WSAENOTSOCK |
|
|
78 | #endif |
|
|
79 | |
76 | static void eio_destroy (eio_req *req); |
80 | static void eio_destroy (eio_req *req); |
77 | |
81 | |
78 | #ifndef EIO_FINISH |
82 | #ifndef EIO_FINISH |
79 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
83 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
80 | #endif |
84 | #endif |
… | |
… | |
101 | #ifdef _WIN32 |
105 | #ifdef _WIN32 |
102 | |
106 | |
103 | #undef PAGESIZE |
107 | #undef PAGESIZE |
104 | #define PAGESIZE 4096 /* GetSystemInfo? */ |
108 | #define PAGESIZE 4096 /* GetSystemInfo? */ |
105 | |
109 | |
|
|
110 | /* TODO: look at how perl does stat (non-sloppy), unlink (ro-files), utime, link */ |
|
|
111 | |
106 | #ifdef EIO_STRUCT_STATI64 |
112 | #ifdef EIO_STRUCT_STATI64 |
|
|
113 | /* look at perl's non-sloppy stat */ |
107 | #define stat(path,buf) _stati64 (path,buf) |
114 | #define stat(path,buf) _stati64 (path,buf) |
108 | #define fstat(fd,buf) _fstati64 (path,buf) |
115 | #define fstat(fd,buf) _fstati64 (fd,buf) |
109 | #endif |
116 | #endif |
110 | #define lstat(path,buf) stat (path,buf) |
117 | #define lstat(path,buf) stat (path,buf) |
111 | #define fsync(fd) (FlushFileBuffers ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1)) |
118 | #define fsync(fd) (FlushFileBuffers ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1)) |
112 | #define mkdir(path,mode) _mkdir (path) |
119 | #define mkdir(path,mode) _mkdir (path) |
113 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
120 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
… | |
… | |
125 | #define sync() EIO_ENOSYS () |
132 | #define sync() EIO_ENOSYS () |
126 | #define readlink(path,buf,s) EIO_ENOSYS () |
133 | #define readlink(path,buf,s) EIO_ENOSYS () |
127 | #define statvfs(path,buf) EIO_ENOSYS () |
134 | #define statvfs(path,buf) EIO_ENOSYS () |
128 | #define fstatvfs(fd,buf) EIO_ENOSYS () |
135 | #define fstatvfs(fd,buf) EIO_ENOSYS () |
129 | |
136 | |
|
|
137 | /* rename() uses MoveFile, which fails to overwrite */ |
|
|
138 | #define rename(old,neu) eio__rename (old, neu) |
|
|
139 | |
|
|
140 | static int |
|
|
141 | eio__rename (const char *old, const char *neu) |
|
|
142 | { |
|
|
143 | if (MoveFileEx (old, neu, MOVEFILE_REPLACE_EXISTING)) |
|
|
144 | return 0; |
|
|
145 | |
|
|
146 | /* should steal _dosmaperr */ |
|
|
147 | switch (GetLastError ()) |
|
|
148 | { |
|
|
149 | case ERROR_FILE_NOT_FOUND: |
|
|
150 | case ERROR_PATH_NOT_FOUND: |
|
|
151 | case ERROR_INVALID_DRIVE: |
|
|
152 | case ERROR_NO_MORE_FILES: |
|
|
153 | case ERROR_BAD_NETPATH: |
|
|
154 | case ERROR_BAD_NET_NAME: |
|
|
155 | case ERROR_BAD_PATHNAME: |
|
|
156 | case ERROR_FILENAME_EXCED_RANGE: |
|
|
157 | errno = ENOENT; |
|
|
158 | break; |
|
|
159 | |
|
|
160 | default: |
|
|
161 | errno = EACCES; |
|
|
162 | break; |
|
|
163 | } |
|
|
164 | |
|
|
165 | return -1; |
|
|
166 | } |
|
|
167 | |
130 | /* we could even stat and see if it exists */ |
168 | /* we could even stat and see if it exists */ |
131 | static int |
169 | static int |
132 | symlink (const char *old, const char *neu) |
170 | symlink (const char *old, const char *neu) |
133 | { |
171 | { |
134 | #if WINVER >= 0x0600 |
172 | #if WINVER >= 0x0600 |
… | |
… | |
160 | |
198 | |
161 | #include <sys/time.h> |
199 | #include <sys/time.h> |
162 | #include <sys/select.h> |
200 | #include <sys/select.h> |
163 | #include <sys/statvfs.h> |
201 | #include <sys/statvfs.h> |
164 | #include <unistd.h> |
202 | #include <unistd.h> |
165 | #include <utime.h> |
|
|
166 | #include <signal.h> |
203 | #include <signal.h> |
167 | #include <dirent.h> |
204 | #include <dirent.h> |
168 | |
205 | |
169 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
206 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
170 | #include <sys/mman.h> |
207 | #include <sys/mman.h> |
… | |
… | |
192 | |
229 | |
193 | #ifndef EIO_STRUCT_DIRENT |
230 | #ifndef EIO_STRUCT_DIRENT |
194 | #define EIO_STRUCT_DIRENT struct dirent |
231 | #define EIO_STRUCT_DIRENT struct dirent |
195 | #endif |
232 | #endif |
196 | |
233 | |
|
|
234 | #endif |
|
|
235 | |
|
|
236 | #if HAVE_UTIMES |
|
|
237 | # include <utime.h> |
|
|
238 | #endif |
|
|
239 | |
|
|
240 | #if HAVE_SYS_SYSCALL_H |
|
|
241 | # include <sys/syscall.h> |
|
|
242 | #endif |
|
|
243 | |
|
|
244 | #if HAVE_SYS_PRCTL_H |
|
|
245 | # include <sys/prctl.h> |
197 | #endif |
246 | #endif |
198 | |
247 | |
199 | #if HAVE_SENDFILE |
248 | #if HAVE_SENDFILE |
200 | # if __linux |
249 | # if __linux |
201 | # include <sys/sendfile.h> |
250 | # include <sys/sendfile.h> |
… | |
… | |
275 | static void (*done_poll_cb) (void); |
324 | static void (*done_poll_cb) (void); |
276 | |
325 | |
277 | static unsigned int max_poll_time; /* reslock */ |
326 | static unsigned int max_poll_time; /* reslock */ |
278 | static unsigned int max_poll_reqs; /* reslock */ |
327 | static unsigned int max_poll_reqs; /* reslock */ |
279 | |
328 | |
280 | static volatile unsigned int nreqs; /* reqlock */ |
329 | static unsigned int nreqs; /* reqlock */ |
281 | static volatile unsigned int nready; /* reqlock */ |
330 | static unsigned int nready; /* reqlock */ |
282 | static volatile unsigned int npending; /* reqlock */ |
331 | static unsigned int npending; /* reqlock */ |
283 | static volatile unsigned int max_idle = 4; /* maximum number of threads that can idle indefinitely */ |
332 | static unsigned int max_idle = 4; /* maximum number of threads that can idle indefinitely */ |
284 | static volatile unsigned int idle_timeout = 10; /* number of seconds after which an idle threads exit */ |
333 | static unsigned int idle_timeout = 10; /* number of seconds after which an idle threads exit */ |
285 | |
334 | |
286 | static xmutex_t wrklock; |
335 | static xmutex_t wrklock; |
287 | static xmutex_t reslock; |
336 | static xmutex_t reslock; |
288 | static xmutex_t reqlock; |
337 | static xmutex_t reqlock; |
289 | static xcond_t reqwait; |
338 | static xcond_t reqwait; |
… | |
… | |
929 | |
978 | |
930 | #if !HAVE_FDATASYNC |
979 | #if !HAVE_FDATASYNC |
931 | # undef fdatasync |
980 | # undef fdatasync |
932 | # define fdatasync(fd) fsync (fd) |
981 | # define fdatasync(fd) fsync (fd) |
933 | #endif |
982 | #endif |
|
|
983 | |
|
|
984 | static int |
|
|
985 | eio__syncfs (int fd) |
|
|
986 | { |
|
|
987 | int res; |
|
|
988 | |
|
|
989 | #if HAVE_SYS_SYNCFS |
|
|
990 | res = (int)syscall (__NR_syncfs, (int)(fd)); |
|
|
991 | #else |
|
|
992 | res = -1; |
|
|
993 | errno = ENOSYS; |
|
|
994 | #endif |
|
|
995 | |
|
|
996 | if (res < 0 && errno == ENOSYS && fd >= 0) |
|
|
997 | sync (); |
|
|
998 | |
|
|
999 | return res; |
|
|
1000 | } |
934 | |
1001 | |
935 | /* sync_file_range always needs emulation */ |
1002 | /* sync_file_range always needs emulation */ |
936 | static int |
1003 | static int |
937 | eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags) |
1004 | eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags) |
938 | { |
1005 | { |
… | |
… | |
1641 | |
1708 | |
1642 | if (dirp == INVALID_HANDLE_VALUE) |
1709 | if (dirp == INVALID_HANDLE_VALUE) |
1643 | { |
1710 | { |
1644 | dirp = 0; |
1711 | dirp = 0; |
1645 | |
1712 | |
|
|
1713 | /* should steal _dosmaperr */ |
1646 | switch (GetLastError ()) |
1714 | switch (GetLastError ()) |
1647 | { |
1715 | { |
1648 | case ERROR_FILE_NOT_FOUND: |
1716 | case ERROR_FILE_NOT_FOUND: |
1649 | req->result = 0; |
1717 | req->result = 0; |
1650 | break; |
1718 | break; |
… | |
… | |
1884 | { |
1952 | { |
1885 | ETP_REQ *req; |
1953 | ETP_REQ *req; |
1886 | struct timespec ts; |
1954 | struct timespec ts; |
1887 | etp_worker *self = (etp_worker *)thr_arg; |
1955 | etp_worker *self = (etp_worker *)thr_arg; |
1888 | |
1956 | |
|
|
1957 | #if HAVE_PRCTL_SET_NAME |
|
|
1958 | prctl (PR_SET_NAME, (unsigned long)"eio_thread", 0, 0, 0); |
|
|
1959 | #endif |
|
|
1960 | |
1889 | /* try to distribute timeouts somewhat evenly */ |
1961 | /* try to distribute timeouts somewhat evenly */ |
1890 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
1962 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
1891 | |
1963 | |
1892 | for (;;) |
1964 | for (;;) |
1893 | { |
1965 | { |
… | |
… | |
2060 | req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; |
2132 | req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; |
2061 | |
2133 | |
2062 | case EIO_SYNC: req->result = 0; sync (); break; |
2134 | case EIO_SYNC: req->result = 0; sync (); break; |
2063 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
2135 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
2064 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
2136 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
|
|
2137 | case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; |
|
|
2138 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
2065 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
2139 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
2066 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
2140 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
2067 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
2141 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
2068 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
2142 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
2069 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
|
|
2070 | case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; |
2143 | case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; |
2071 | |
2144 | |
2072 | case EIO_READDIR: eio__scandir (req, self); break; |
2145 | case EIO_READDIR: eio__scandir (req, self); break; |
2073 | |
2146 | |
2074 | case EIO_BUSY: |
2147 | case EIO_BUSY: |
… | |
… | |
2155 | eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2228 | eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2156 | { |
2229 | { |
2157 | REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2230 | REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2158 | } |
2231 | } |
2159 | |
2232 | |
|
|
2233 | eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) |
|
|
2234 | { |
|
|
2235 | REQ (EIO_FDATASYNC); req->int1 = fd; SEND; |
|
|
2236 | } |
|
|
2237 | |
|
|
2238 | eio_req *eio_syncfs (int fd, int pri, eio_cb cb, void *data) |
|
|
2239 | { |
|
|
2240 | REQ (EIO_SYNCFS); req->int1 = fd; SEND; |
|
|
2241 | } |
|
|
2242 | |
|
|
2243 | eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
|
|
2244 | { |
|
|
2245 | REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; |
|
|
2246 | } |
|
|
2247 | |
2160 | eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2248 | eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2161 | { |
2249 | { |
2162 | REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2250 | REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2163 | } |
2251 | } |
2164 | |
2252 | |
… | |
… | |
2170 | eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data) |
2258 | eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data) |
2171 | { |
2259 | { |
2172 | REQ (EIO_MLOCKALL); req->int1 = flags; SEND; |
2260 | REQ (EIO_MLOCKALL); req->int1 = flags; SEND; |
2173 | } |
2261 | } |
2174 | |
2262 | |
2175 | eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
|
|
2176 | { |
|
|
2177 | REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; |
|
|
2178 | } |
|
|
2179 | |
|
|
2180 | eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data) |
2263 | eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data) |
2181 | { |
2264 | { |
2182 | REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND; |
2265 | REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND; |
2183 | } |
|
|
2184 | |
|
|
2185 | eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) |
|
|
2186 | { |
|
|
2187 | REQ (EIO_FDATASYNC); req->int1 = fd; SEND; |
|
|
2188 | } |
2266 | } |
2189 | |
2267 | |
2190 | eio_req *eio_close (int fd, int pri, eio_cb cb, void *data) |
2268 | eio_req *eio_close (int fd, int pri, eio_cb cb, void *data) |
2191 | { |
2269 | { |
2192 | REQ (EIO_CLOSE); req->int1 = fd; SEND; |
2270 | REQ (EIO_CLOSE); req->int1 = fd; SEND; |