Skip to content

Commit 4d07e43

Browse files
Marc Lehmannkindy
authored andcommitted
[sync]
1 parent 5778b6e commit 4d07e43

File tree

8 files changed

+91
-165
lines changed

8 files changed

+91
-165
lines changed

cvs-vers

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
Changes:1.61
1+
Changes:1.65
22
LICENSE:1.1
33
Makefile.am:1.4
44
aclocal.m4:1.3
55
autogen.sh:1.4
66
configure.ac:1.11
77
demo.c:1.4
8-
ecb.h:1.27
8+
ecb.h:1.28
99
eio.3:1.1
10-
eio.c:1.149
11-
eio.h:1.61
10+
eio.c:1.157
11+
eio.h:1.63
1212
eio.pod:1.36
13-
etp.c:1.11
14-
libeio.m4:1.31
15-
xthread.h:1.18
13+
etp.c:1.14
14+
libeio.m4:1.32
15+
xthread.h:1.19

src/Changes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,9 @@ TODO: pthread_condattr_setclock(..., CLOCK_MONOTONIC) and clock_gettime(CLOCK_MO
8989
- save errno around close in ftruncateat, fstatvfsat and EIO_CLOSE.
9090
- add EIO_SLURP convenience request.
9191
- update configure.ac for newer autoconf/automake.
92+
- include sys/prctl.h if available.
93+
- use O_NONBLOCK when opening directories and in truncateat and statvfsat.
94+
- add EIO_MCL_ONFAULT.
95+
- add eio_mlockall_sync.
9296

9397

src/ecb.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@
117117

118118
#define ECB_CPP (__cplusplus+0)
119119
#define ECB_CPP11 (__cplusplus >= 201103L)
120+
#define ECB_CPP14 (__cplusplus >= 201402L)
121+
#define ECB_CPP17 (__cplusplus >= 201703L)
120122

121123
#if ECB_CPP
122124
#define ECB_C 0
@@ -128,6 +130,7 @@
128130

129131
#define ECB_C99 (ECB_STDC_VERSION >= 199901L)
130132
#define ECB_C11 (ECB_STDC_VERSION >= 201112L)
133+
#define ECB_C17 (ECB_STDC_VERSION >= 201710L)
131134

132135
#if ECB_CPP
133136
#define ECB_EXTERN_C extern "C"
@@ -166,11 +169,11 @@
166169
#if __i386 || __i386__
167170
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
168171
#define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
169-
#define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
172+
#define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
170173
#elif ECB_GCC_AMD64
171174
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
172175
#define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
173-
#define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
176+
#define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
174177
#elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
175178
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
176179
#elif defined __ARM_ARCH_2__ \

src/eio.c

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* libeio implementation
33
*
4-
* Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2016,2017 Marc Alexander Lehmann <libeio@schmorp.de>
4+
* Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2016,2017,2018 Marc Alexander Lehmann <libeio@schmorp.de>
55
* All rights reserved.
66
*
77
* Redistribution and use in source and binary forms, with or without modifica-
@@ -331,6 +331,18 @@ static void eio_destroy (eio_req *req);
331331
#define O_CLOEXEC 0
332332
#endif
333333

334+
#ifndef O_NONBLOCK
335+
#define O_NONBLOCK 0
336+
#endif
337+
338+
#ifndef O_SEARCH
339+
#define O_SEARCH O_RDONLY
340+
#endif
341+
342+
#ifndef O_DIRECTORY
343+
#define O_DIRECTORY 0
344+
#endif
345+
334346
#ifndef EIO_PATH_MIN
335347
# define EIO_PATH_MIN 8160
336348
#endif
@@ -356,9 +368,6 @@ struct etp_tmpbuf;
356368
#if _POSIX_VERSION >= 200809L
357369
#define HAVE_AT 1
358370
#define WD2FD(wd) ((wd) ? (wd)->fd : AT_FDCWD)
359-
#ifndef O_SEARCH
360-
#define O_SEARCH O_RDONLY
361-
#endif
362371
#else
363372
#define HAVE_AT 0
364373
static const char *wd_expand (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path);
@@ -895,12 +904,21 @@ eio__mlockall (int flags)
895904
mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */
896905
#endif
897906

898-
if (EIO_MCL_CURRENT != MCL_CURRENT
899-
|| EIO_MCL_FUTURE != MCL_FUTURE)
907+
#ifndef MCL_ONFAULT
908+
if (flags & EIO_MCL_ONFAULT)
909+
return EIO_ERRNO (EINVAL, -1);
910+
#define MCL_ONFAULT 4
911+
#endif
912+
913+
if (EIO_MCL_CURRENT != MCL_CURRENT
914+
|| EIO_MCL_FUTURE != MCL_FUTURE
915+
|| EIO_MCL_ONFAULT != MCL_ONFAULT)
900916
{
901917
flags = 0
902918
| (flags & EIO_MCL_CURRENT ? MCL_CURRENT : 0)
903-
| (flags & EIO_MCL_FUTURE ? MCL_FUTURE : 0);
919+
| (flags & EIO_MCL_FUTURE ? MCL_FUTURE : 0)
920+
| (flags & EIO_MCL_ONFAULT ? MCL_ONFAULT : 0)
921+
;
904922
}
905923

906924
return mlockall (flags);
@@ -961,9 +979,9 @@ eio__mtouch (eio_req *req)
961979

962980
if (addr < end)
963981
if (flags & EIO_MT_MODIFY) /* modify */
964-
do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req));
982+
do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < end && !EIO_CANCELLED (req));
965983
else
966-
do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req));
984+
do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < end && !EIO_CANCELLED (req));
967985
}
968986

969987
return 0;
@@ -1397,26 +1415,26 @@ eio__scandir (eio_req *req, etp_worker *self)
13971415
}
13981416
#else
13991417
#if HAVE_AT
1400-
if (req->wd)
1401-
{
1402-
int fd = openat (WD2FD (req->wd), req->ptr1, O_CLOEXEC | O_SEARCH | O_DIRECTORY);
1418+
{
1419+
int fd = openat (WD2FD (req->wd), req->ptr1, O_CLOEXEC | O_SEARCH | O_DIRECTORY | O_NONBLOCK);
14031420

1404-
if (fd < 0)
1405-
return;
1421+
if (fd < 0)
1422+
return;
14061423

1407-
dirp = fdopendir (fd);
1424+
dirp = fdopendir (fd);
14081425

1409-
if (!dirp)
1426+
if (!dirp)
1427+
{
14101428
silent_close (fd);
1411-
}
1412-
else
1413-
dirp = opendir (req->ptr1);
1429+
return;
1430+
}
1431+
}
14141432
#else
14151433
dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1));
1416-
#endif
14171434

1418-
if (!dirp)
1419-
return;
1435+
if (!dirp)
1436+
return;
1437+
#endif
14201438
#endif
14211439

14221440
if (req->flags & EIO_FLAG_PTR1_FREE)
@@ -1661,7 +1679,7 @@ eio__wd_open_sync (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path)
16611679
return EIO_INVALID_WD;
16621680

16631681
#if HAVE_AT
1664-
fd = openat (WD2FD (wd), path, O_CLOEXEC | O_SEARCH | O_DIRECTORY);
1682+
fd = openat (WD2FD (wd), path, O_CLOEXEC | O_SEARCH | O_DIRECTORY | O_NONBLOCK);
16651683

16661684
if (fd < 0)
16671685
return EIO_INVALID_WD;
@@ -1683,7 +1701,7 @@ eio__wd_open_sync (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path)
16831701
eio_wd
16841702
eio_wd_open_sync (eio_wd wd, const char *path)
16851703
{
1686-
struct etp_tmpbuf tmpbuf = { };
1704+
struct etp_tmpbuf tmpbuf = { 0 };
16871705
wd = eio__wd_open_sync (&tmpbuf, wd, path);
16881706
free (tmpbuf.ptr);
16891707

@@ -1722,7 +1740,7 @@ eio__renameat2 (int olddirfd, const char *oldpath, int newdirfd, const char *new
17221740
static int
17231741
eio__truncateat (int dirfd, const char *path, off_t length)
17241742
{
1725-
int fd = openat (dirfd, path, O_WRONLY | O_CLOEXEC);
1743+
int fd = openat (dirfd, path, O_WRONLY | O_CLOEXEC | O_NONBLOCK);
17261744
int res;
17271745

17281746
if (fd < 0)
@@ -1736,7 +1754,7 @@ eio__truncateat (int dirfd, const char *path, off_t length)
17361754
static int
17371755
eio__statvfsat (int dirfd, const char *path, struct statvfs *buf)
17381756
{
1739-
int fd = openat (dirfd, path, O_SEARCH | O_CLOEXEC);
1757+
int fd = openat (dirfd, path, O_SEARCH | O_CLOEXEC | O_NONBLOCK);
17401758
int res;
17411759

17421760
if (fd < 0)
@@ -2411,3 +2429,8 @@ eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count)
24112429
return eio__sendfile (ofd, ifd, offset, count);
24122430
}
24132431

2432+
int eio_mlockall_sync (int flags)
2433+
{
2434+
return eio__mlockall (flags);
2435+
}
2436+

src/eio.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ enum
242242
enum
243243
{
244244
EIO_MCL_CURRENT = 1,
245-
EIO_MCL_FUTURE = 2
245+
EIO_MCL_FUTURE = 2,
246+
EIO_MCL_ONFAULT = 4
246247
};
247248

248249
/* request priorities */
@@ -420,6 +421,7 @@ void eio_cancel (eio_req *req);
420421
/* convenience functions */
421422

422423
eio_ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count);
424+
int eio_mlockall_sync (int flags);
423425

424426
#ifdef __cplusplus
425427
}

src/etp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ etp_proc_init (void)
320320
{
321321
#if HAVE_PRCTL_SET_NAME
322322
/* provide a more sensible "thread name" */
323-
char name[15 + 1];
323+
char name[16 + 1];
324324
const int namelen = sizeof (name) - 1;
325325
int len;
326326

src/libeio.m4

Lines changed: 5 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dnl openbsd in it's neverending brokenness requires stdint.h for intptr_t,
1+
dnl openbsd in its neverending brokenness requires stdint.h for intptr_t,
22
dnl but that header isn't very portable...
33
AC_CHECK_HEADERS([stdint.h sys/syscall.h sys/prctl.h])
44

@@ -142,108 +142,16 @@ int main (void)
142142
])],ac_cv_prctl_set_name=yes,ac_cv_prctl_set_name=no)])
143143
test $ac_cv_prctl_set_name = yes && AC_DEFINE(HAVE_PRCTL_SET_NAME, 1, prctl(PR_SET_NAME) is available)
144144

145-
dnl #############################################################################
146-
dnl # these checks exist for the benefit of IO::AIO
147-
148-
AC_CACHE_CHECK(for set/getrlimit, ac_cv_rlimits, [AC_LINK_IFELSE([AC_LANG_SOURCE([[
149-
#include <sys/time.h>
150-
#include <sys/resource.h>
151-
int res;
152-
int main (void)
153-
{
154-
struct rlimit srl;
155-
srl.rlim_cur = srl.rlim_max = RLIM_INFINITY;
156-
res = getrlimit (RLIMIT_NOFILE, &srl);
157-
res = setrlimit (RLIMIT_NOFILE, &srl);
158-
return 0;
159-
}
160-
]])],ac_cv_rlimits=yes,ac_cv_rlimits=no)])
161-
test $ac_cv_rlimits = yes && AC_DEFINE(HAVE_RLIMITS, 1, setrlimit/getrlimit is available)
162-
163-
dnl at least uclibc defines _POSIX_ADVISORY_INFO without *any* of the required
164-
dnl functionality actually being present. ugh.
165-
AC_CACHE_CHECK(for posix_madvise, ac_cv_posix_madvise, [AC_LINK_IFELSE([AC_LANG_SOURCE([
166-
#include <sys/mman.h>
167-
int main (void)
168-
{
169-
int res = posix_madvise ((void *)0, (size_t)0, POSIX_MADV_NORMAL);
170-
int a = POSIX_MADV_SEQUENTIAL;
171-
int b = POSIX_MADV_RANDOM;
172-
int c = POSIX_MADV_WILLNEED;
173-
int d = POSIX_MADV_DONTNEED;
174-
return 0;
175-
}
176-
])],ac_cv_posix_madvise=yes,ac_cv_posix_madvise=no)])
177-
test $ac_cv_posix_madvise = yes && AC_DEFINE(HAVE_POSIX_MADVISE, 1, posix_madvise(2) is available)
178-
179-
AC_CACHE_CHECK(for posix_fadvise, ac_cv_posix_fadvise, [AC_LINK_IFELSE([AC_LANG_SOURCE([
180-
#define _XOPEN_SOURCE 600
181-
#include <fcntl.h>
182-
int main (void)
183-
{
184-
int res = posix_fadvise ((int)0, (off_t)0, (off_t)0, POSIX_FADV_NORMAL);
185-
int a = POSIX_FADV_SEQUENTIAL;
186-
int b = POSIX_FADV_NOREUSE;
187-
int c = POSIX_FADV_RANDOM;
188-
int d = POSIX_FADV_WILLNEED;
189-
int e = POSIX_FADV_DONTNEED;
190-
return 0;
191-
}
192-
])],ac_cv_posix_fadvise=yes,ac_cv_posix_fadvise=no)])
193-
test $ac_cv_posix_fadvise = yes && AC_DEFINE(HAVE_POSIX_FADVISE, 1, posix_fadvise(2) is available)
194-
195-
dnl lots of linux specifics
196-
AC_CHECK_HEADERS([linux/fs.h linux/fiemap.h])
197-
198-
AC_CACHE_CHECK([for splice, vmsplice and tee], ac_cv_linux_splice, [AC_LINK_IFELSE([AC_LANG_SOURCE([
199-
#include <fcntl.h>
200-
int main (void)
201-
{
202-
ssize_t res;
203-
res = splice ((int)0, (loff_t)0, (int)0, (loff_t *)0, (size_t)0, SPLICE_F_MOVE | SPLICE_F_NONBLOCK | SPLICE_F_MORE);
204-
res = tee ((int)0, (int)0, (size_t)0, SPLICE_F_NONBLOCK);
205-
res = vmsplice ((int)0, (struct iovec *)0, 0, SPLICE_F_NONBLOCK | SPLICE_F_GIFT);
206-
return 0;
207-
}
208-
])],ac_cv_linux_splice=yes,ac_cv_linux_splice=no)])
209-
test $ac_cv_linux_splice = yes && AC_DEFINE(HAVE_LINUX_SPLICE, 1, splice/vmsplice/tee(2) are available)
210-
211-
AC_CACHE_CHECK(for pipe2, ac_cv_pipe2, [AC_LINK_IFELSE([AC_LANG_SOURCE([[
212-
#include <fcntl.h>
145+
AC_CACHE_CHECK(for posix_close, ac_cv_posix_close, [AC_LINK_IFELSE([AC_LANG_SOURCE([[
213146
#include <unistd.h>
214147
int res;
215148
int main (void)
216149
{
217-
res = pipe2 (0, 0);
218-
return 0;
219-
}
220-
]])],ac_cv_pipe2=yes,ac_cv_pipe2=no)])
221-
test $ac_cv_pipe2 = yes && AC_DEFINE(HAVE_PIPE2, 1, pipe2(2) is available)
222-
223-
AC_CACHE_CHECK(for eventfd, ac_cv_eventfd, [AC_LINK_IFELSE([AC_LANG_SOURCE([[
224-
#include <sys/eventfd.h>
225-
int res;
226-
int main (void)
227-
{
228-
res = eventfd (1, EFD_CLOEXEC | EFD_NONBLOCK);
229-
return 0;
230-
}
231-
]])],ac_cv_eventfd=yes,ac_cv_eventfd=no)])
232-
test $ac_cv_eventfd = yes && AC_DEFINE(HAVE_EVENTFD, 1, eventfd(2) is available)
233-
234-
AC_CACHE_CHECK(for timerfd, ac_cv_timerfd, [AC_LINK_IFELSE([AC_LANG_SOURCE([[
235-
#include <sys/timerfd.h>
236-
int res;
237-
int main (void)
238-
{
239-
struct itimerspec its;
240-
res = timerfd_create (CLOCK_REALTIME, TFD_CLOEXEC | TFD_NONBLOCK);
241-
res = timerfd_settime (res, TFD_TIMER_ABSTIME /*| TFD_TIMER_CANCEL_ON_SET*/, &its, 0);
242-
res = timerfd_gettime (res, &its);
150+
res = posix_close (0, 0); /* we do not need any flags */
243151
return 0;
244152
}
245-
]])],ac_cv_timerfd=yes,ac_cv_timerfd=no)])
246-
test $ac_cv_timerfd = yes && AC_DEFINE(HAVE_TIMERFD, 1, timerfd_*(2) are available)
153+
]])],ac_cv_posix_close=yes,ac_cv_posix_close=no)])
154+
test $ac_cv_posix_close = yes && AC_DEFINE(HAVE_POSIX_CLOSE, 1, posix_close(2) is available)
247155

248156
AC_CACHE_CHECK(for renameat2, ac_cv_renameat2, [AC_LINK_IFELSE([AC_LANG_SOURCE([[
249157
#include <unistd.h>
@@ -258,28 +166,3 @@ int main (void)
258166
]])],ac_cv_renameat2=yes,ac_cv_renameat2=no)])
259167
test $ac_cv_renameat2 = yes && AC_DEFINE(HAVE_RENAMEAT2, 1, renameat2(2) is available)
260168

261-
AC_CACHE_CHECK(for copy_file_range, ac_cv_copy_file_range, [AC_LINK_IFELSE([AC_LANG_SOURCE([[
262-
#include <unistd.h>
263-
#include <sys/syscall.h>
264-
/*#include <linux/copy.h>*/
265-
int res;
266-
int main (void)
267-
{
268-
/*res = syscall (SYS_copy_file_range, 0, 0, 0, 0, 0, COPY_FR_REFLINK | COPY_FR_DEDUP | COPY_FR_COPY);*/
269-
res = syscall (SYS_copy_file_range, 0, 0, 0, 0, 0, 0);
270-
return 0;
271-
}
272-
]])],ac_cv_copy_file_range=yes,ac_cv_copy_file_range=no)])
273-
test $ac_cv_copy_file_range = yes && AC_DEFINE(HAVE_COPY_FILE_RANGE, 1, copy_file_range(2) is available)
274-
275-
AC_CACHE_CHECK(for posix_close, ac_cv_posix_close, [AC_LINK_IFELSE([AC_LANG_SOURCE([[
276-
#include <unistd.h>
277-
int res;
278-
int main (void)
279-
{
280-
res = posix_close (0, 0); /* we do not need any flags */
281-
return 0;
282-
}
283-
]])],ac_cv_posix_close=yes,ac_cv_posix_close=no)])
284-
test $ac_cv_posix_close = yes && AC_DEFINE(HAVE_POSIX_CLOSE, 1, posix_close(2) is available)
285-

0 commit comments

Comments
 (0)