ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libeio/eio.c
(Generate patch)

Comparing cvsroot/libeio/eio.c (file contents):
Revision 1.66 by root, Sun Jun 5 19:58:37 2011 UTC vs.
Revision 1.90 by root, Sat Jul 16 16:46:10 2011 UTC

40#ifndef _WIN32 40#ifndef _WIN32
41# include "config.h" 41# include "config.h"
42#endif 42#endif
43 43
44#include "eio.h" 44#include "eio.h"
45#include "ecb.h"
45 46
46#ifdef EIO_STACKSIZE 47#ifdef EIO_STACKSIZE
47# define XTHREAD_STACKSIZE EIO_STACKSIZE 48# define XTHREAD_STACKSIZE EIO_STACKSIZE
48#endif 49#endif
49#include "xthread.h" 50#include "xthread.h"
53#include <stdlib.h> 54#include <stdlib.h>
54#include <string.h> 55#include <string.h>
55#include <errno.h> 56#include <errno.h>
56#include <sys/types.h> 57#include <sys/types.h>
57#include <sys/stat.h> 58#include <sys/stat.h>
58#include <sys/statvfs.h>
59#include <limits.h> 59#include <limits.h>
60#include <fcntl.h> 60#include <fcntl.h>
61#include <assert.h> 61#include <assert.h>
62 62
63/* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ 63/* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */
64/* intptr_t only comes form stdint.h, says idiot openbsd coder */ 64/* intptr_t only comes from stdint.h, says idiot openbsd coder */
65#if HAVE_STDINT_H 65#if HAVE_STDINT_H
66# include <stdint.h> 66# include <stdint.h>
67#endif 67#endif
68 68
69#ifndef ECANCELED
70# define ECANCELED EDOM
71#endif
72#ifndef ELOOP
73# define ELOOP EDOM
74#endif
75
76static void eio_destroy (eio_req *req);
77
69#ifndef EIO_FINISH 78#ifndef EIO_FINISH
70# define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 79# define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0
71#endif 80#endif
72 81
73#ifndef EIO_DESTROY 82#ifndef EIO_DESTROY
76 85
77#ifndef EIO_FEED 86#ifndef EIO_FEED
78# define EIO_FEED(req) do { if ((req)->feed ) (req)->feed (req); } while (0) 87# define EIO_FEED(req) do { if ((req)->feed ) (req)->feed (req); } while (0)
79#endif 88#endif
80 89
90#ifndef EIO_FD_TO_WIN32_HANDLE
91# define EIO_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd)
92#endif
93#ifndef EIO_WIN32_HANDLE_TO_FD
94# define EIO_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (handle, 0)
95#endif
96
97#define EIO_ERRNO(errval,retval) ((errno = errval), retval)
98
99#define EIO_ENOSYS() EIO_ERRNO (ENOSYS, -1)
100
81#ifdef _WIN32 101#ifdef _WIN32
82 102
83 /*doh*/ 103 #undef PAGESIZE
104 #define PAGESIZE 4096 /* GetSystemInfo? */
105
106 #ifdef EIO_STRUCT_STATI64
107 #define stat(path,buf) _stati64 (path,buf)
108 #define fstat(fd,buf) _fstati64 (path,buf)
109 #endif
110 #define lstat(path,buf) stat (path,buf)
111 #define fsync(fd) (FlushFileBuffers ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1))
112 #define mkdir(path,mode) _mkdir (path)
113 #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1))
114
115 #define chmod(path,mode) _chmod (path, mode)
116 #define fchmod(fd,mode) EIO_ENOSYS ()
117 #define chown(path,uid,gid) EIO_ENOSYS ()
118 #define fchown(fd,uid,gid) EIO_ENOSYS ()
119 #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */
120 #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */
121 #define mknod(path,mode,dev) EIO_ENOSYS ()
122 #define sync() EIO_ENOSYS ()
123 #define readlink(path,buf,s) EIO_ENOSYS ()
124 #define statvfs(path,buf) EIO_ENOSYS ()
125 #define fstatvfs(fd,buf) EIO_ENOSYS ()
126
127 /* we could even stat and see if it exists */
128 static int
129 symlink (const char *old, const char *neu)
130 {
131 #if WINVER >= 0x0600
132 if (CreateSymbolicLink (neu, old, 1))
133 return 0;
134
135 if (CreateSymbolicLink (neu, old, 0))
136 return 0;
137 #endif
138
139 return EIO_ERRNO (ENOENT, -1);
140 }
141
142 /* POSIX API only */
143 #define CreateHardLink(neu,old) 0
144 #define CreateSymbolicLink(neu,old,flags) 0
145
146 struct statvfs
147 {
148 int dummy;
149 };
150
84#else 151#else
85 152
86# include <sys/time.h> 153 #include <sys/time.h>
87# include <sys/select.h> 154 #include <sys/select.h>
155 #include <sys/statvfs.h>
88# include <unistd.h> 156 #include <unistd.h>
89# include <utime.h> 157 #include <utime.h>
90# include <signal.h> 158 #include <signal.h>
91# include <dirent.h> 159 #include <dirent.h>
92 160
93#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES 161 #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
94# include <sys/mman.h> 162 #include <sys/mman.h>
95#endif 163 #endif
96 164
97/* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ 165 /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */
98# if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ 166 #if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
99# define _DIRENT_HAVE_D_TYPE /* sigh */ 167 #define _DIRENT_HAVE_D_TYPE /* sigh */
100# define D_INO(de) (de)->d_fileno 168 #define D_INO(de) (de)->d_fileno
101# define D_NAMLEN(de) (de)->d_namlen 169 #define D_NAMLEN(de) (de)->d_namlen
102# elif __linux || defined d_ino || _XOPEN_SOURCE >= 600 170 #elif __linux || defined d_ino || _XOPEN_SOURCE >= 600
103# define D_INO(de) (de)->d_ino 171 #define D_INO(de) (de)->d_ino
104# endif 172 #endif
105 173
106#ifdef _D_EXACT_NAMLEN 174 #ifdef _D_EXACT_NAMLEN
107# undef D_NAMLEN 175 #undef D_NAMLEN
108# define D_NAMLEN(de) _D_EXACT_NAMLEN (de) 176 #define D_NAMLEN(de) _D_EXACT_NAMLEN (de)
109#endif 177 #endif
110 178
111# ifdef _DIRENT_HAVE_D_TYPE 179 #ifdef _DIRENT_HAVE_D_TYPE
112# define D_TYPE(de) (de)->d_type 180 #define D_TYPE(de) (de)->d_type
113# endif 181 #endif
114 182
115# ifndef EIO_STRUCT_DIRENT 183 #ifndef EIO_STRUCT_DIRENT
116# define EIO_STRUCT_DIRENT struct dirent 184 #define EIO_STRUCT_DIRENT struct dirent
117# endif 185 #endif
118 186
119#endif 187#endif
120 188
121#if HAVE_SENDFILE 189#if HAVE_SENDFILE
122# if __linux 190# if __linux
165 if (!eio_buf) \ 233 if (!eio_buf) \
166 return -1; 234 return -1;
167 235
168#define EIO_TICKS ((1000000 + 1023) >> 10) 236#define EIO_TICKS ((1000000 + 1023) >> 10)
169 237
170/*****************************************************************************/
171
172#if __GNUC__ >= 3
173# define expect(expr,value) __builtin_expect ((expr),(value))
174#else
175# define expect(expr,value) (expr)
176#endif
177
178#define expect_false(expr) expect ((expr) != 0, 0)
179#define expect_true(expr) expect ((expr) != 0, 1)
180
181/*****************************************************************************/
182
183#define ETP_PRI_MIN EIO_PRI_MIN 238#define ETP_PRI_MIN EIO_PRI_MIN
184#define ETP_PRI_MAX EIO_PRI_MAX 239#define ETP_PRI_MAX EIO_PRI_MAX
185 240
186struct etp_worker; 241struct etp_worker;
187 242
212/*****************************************************************************/ 267/*****************************************************************************/
213 268
214#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) 269#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1)
215 270
216/* calculate time difference in ~1/EIO_TICKS of a second */ 271/* calculate time difference in ~1/EIO_TICKS of a second */
272ecb_inline int
217static int tvdiff (struct timeval *tv1, struct timeval *tv2) 273tvdiff (struct timeval *tv1, struct timeval *tv2)
218{ 274{
219 return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS 275 return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS
220 + ((tv2->tv_usec - tv1->tv_usec) >> 10); 276 + ((tv2->tv_usec - tv1->tv_usec) >> 10);
221} 277}
222 278
266#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock) 322#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock)
267#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock) 323#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock)
268 324
269/* worker threads management */ 325/* worker threads management */
270 326
327static void ecb_cold
271static void etp_worker_clear (etp_worker *wrk) 328etp_worker_clear (etp_worker *wrk)
272{ 329{
273 ETP_WORKER_CLEAR (wrk); 330 ETP_WORKER_CLEAR (wrk);
274} 331}
275 332
333static void ecb_cold
276static void etp_worker_free (etp_worker *wrk) 334etp_worker_free (etp_worker *wrk)
277{ 335{
278 wrk->next->prev = wrk->prev; 336 wrk->next->prev = wrk->prev;
279 wrk->prev->next = wrk->next; 337 wrk->prev->next = wrk->next;
280 338
281 free (wrk); 339 free (wrk);
282} 340}
283 341
284static unsigned int etp_nreqs (void) 342static unsigned int
343etp_nreqs (void)
285{ 344{
286 int retval; 345 int retval;
287 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 346 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
288 retval = nreqs; 347 retval = nreqs;
289 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 348 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
290 return retval; 349 return retval;
291} 350}
292 351
293static unsigned int etp_nready (void) 352static unsigned int
353etp_nready (void)
294{ 354{
295 unsigned int retval; 355 unsigned int retval;
296 356
297 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 357 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
298 retval = nready; 358 retval = nready;
299 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 359 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
300 360
301 return retval; 361 return retval;
302} 362}
303 363
304static unsigned int etp_npending (void) 364static unsigned int
365etp_npending (void)
305{ 366{
306 unsigned int retval; 367 unsigned int retval;
307 368
308 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 369 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
309 retval = npending; 370 retval = npending;
310 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 371 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
311 372
312 return retval; 373 return retval;
313} 374}
314 375
315static unsigned int etp_nthreads (void) 376static unsigned int
377etp_nthreads (void)
316{ 378{
317 unsigned int retval; 379 unsigned int retval;
318 380
319 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 381 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
320 retval = started; 382 retval = started;
334} etp_reqq; 396} etp_reqq;
335 397
336static etp_reqq req_queue; 398static etp_reqq req_queue;
337static etp_reqq res_queue; 399static etp_reqq res_queue;
338 400
401static int ecb_noinline
339static int reqq_push (etp_reqq *q, ETP_REQ *req) 402reqq_push (etp_reqq *q, ETP_REQ *req)
340{ 403{
341 int pri = req->pri; 404 int pri = req->pri;
342 req->next = 0; 405 req->next = 0;
343 406
344 if (q->qe[pri]) 407 if (q->qe[pri])
350 q->qe[pri] = q->qs[pri] = req; 413 q->qe[pri] = q->qs[pri] = req;
351 414
352 return q->size++; 415 return q->size++;
353} 416}
354 417
418static ETP_REQ * ecb_noinline
355static ETP_REQ *reqq_shift (etp_reqq *q) 419reqq_shift (etp_reqq *q)
356{ 420{
357 int pri; 421 int pri;
358 422
359 if (!q->size) 423 if (!q->size)
360 return 0; 424 return 0;
375 } 439 }
376 440
377 abort (); 441 abort ();
378} 442}
379 443
444static void ecb_cold
380static void etp_thread_init (void) 445etp_thread_init (void)
381{ 446{
447#if !HAVE_PREADWRITE
448 X_MUTEX_CREATE (preadwritelock);
449#endif
382 X_MUTEX_CREATE (wrklock); 450 X_MUTEX_CREATE (wrklock);
383 X_MUTEX_CREATE (reslock); 451 X_MUTEX_CREATE (reslock);
384 X_MUTEX_CREATE (reqlock); 452 X_MUTEX_CREATE (reqlock);
385 X_COND_CREATE (reqwait); 453 X_COND_CREATE (reqwait);
386} 454}
387 455
456static void ecb_cold
388static void etp_atfork_prepare (void) 457etp_atfork_prepare (void)
389{ 458{
390 X_LOCK (wrklock);
391 X_LOCK (reqlock);
392 X_LOCK (reslock);
393#if !HAVE_PREADWRITE
394 X_LOCK (preadwritelock);
395#endif
396} 459}
397 460
461static void ecb_cold
398static void etp_atfork_parent (void) 462etp_atfork_parent (void)
399{ 463{
400#if !HAVE_PREADWRITE
401 X_UNLOCK (preadwritelock);
402#endif
403 X_UNLOCK (reslock);
404 X_UNLOCK (reqlock);
405 X_UNLOCK (wrklock);
406} 464}
407 465
466static void ecb_cold
408static void etp_atfork_child (void) 467etp_atfork_child (void)
409{ 468{
410 ETP_REQ *prv; 469 ETP_REQ *prv;
411 470
412 while ((prv = reqq_shift (&req_queue))) 471 while ((prv = reqq_shift (&req_queue)))
413 ETP_DESTROY (prv); 472 ETP_DESTROY (prv);
433 npending = 0; 492 npending = 0;
434 493
435 etp_thread_init (); 494 etp_thread_init ();
436} 495}
437 496
438static void 497static void ecb_cold
439etp_once_init (void) 498etp_once_init (void)
440{ 499{
441 etp_thread_init (); 500 etp_thread_init ();
442 X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child); 501 X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child);
443} 502}
444 503
445static int 504static int ecb_cold
446etp_init (void (*want_poll)(void), void (*done_poll)(void)) 505etp_init (void (*want_poll)(void), void (*done_poll)(void))
447{ 506{
448 static pthread_once_t doinit = PTHREAD_ONCE_INIT; 507 static pthread_once_t doinit = PTHREAD_ONCE_INIT;
449 508
450 pthread_once (&doinit, etp_once_init); 509 pthread_once (&doinit, etp_once_init);
455 return 0; 514 return 0;
456} 515}
457 516
458X_THREAD_PROC (etp_proc); 517X_THREAD_PROC (etp_proc);
459 518
519static void ecb_cold
460static void etp_start_thread (void) 520etp_start_thread (void)
461{ 521{
462 etp_worker *wrk = calloc (1, sizeof (etp_worker)); 522 etp_worker *wrk = calloc (1, sizeof (etp_worker));
463 523
464 /*TODO*/ 524 /*TODO*/
465 assert (("unable to allocate worker thread data", wrk)); 525 assert (("unable to allocate worker thread data", wrk));
478 free (wrk); 538 free (wrk);
479 539
480 X_UNLOCK (wrklock); 540 X_UNLOCK (wrklock);
481} 541}
482 542
543static void
483static void etp_maybe_start_thread (void) 544etp_maybe_start_thread (void)
484{ 545{
485 if (expect_true (etp_nthreads () >= wanted)) 546 if (ecb_expect_true (etp_nthreads () >= wanted))
486 return; 547 return;
487 548
488 /* todo: maybe use idle here, but might be less exact */ 549 /* todo: maybe use idle here, but might be less exact */
489 if (expect_true (0 <= (int)etp_nthreads () + (int)etp_npending () - (int)etp_nreqs ())) 550 if (ecb_expect_true (0 <= (int)etp_nthreads () + (int)etp_npending () - (int)etp_nreqs ()))
490 return; 551 return;
491 552
492 etp_start_thread (); 553 etp_start_thread ();
493} 554}
494 555
556static void ecb_cold
495static void etp_end_thread (void) 557etp_end_thread (void)
496{ 558{
497 eio_req *req = calloc (1, sizeof (eio_req)); 559 eio_req *req = calloc (1, sizeof (eio_req));
498 560
499 req->type = -1; 561 req->type = -1;
500 req->pri = ETP_PRI_MAX - ETP_PRI_MIN; 562 req->pri = ETP_PRI_MAX - ETP_PRI_MIN;
507 X_LOCK (wrklock); 569 X_LOCK (wrklock);
508 --started; 570 --started;
509 X_UNLOCK (wrklock); 571 X_UNLOCK (wrklock);
510} 572}
511 573
512static int etp_poll (void) 574static int
575etp_poll (void)
513{ 576{
514 unsigned int maxreqs; 577 unsigned int maxreqs;
515 unsigned int maxtime; 578 unsigned int maxtime;
516 struct timeval tv_start, tv_now; 579 struct timeval tv_start, tv_now;
517 580
547 610
548 X_LOCK (reqlock); 611 X_LOCK (reqlock);
549 --nreqs; 612 --nreqs;
550 X_UNLOCK (reqlock); 613 X_UNLOCK (reqlock);
551 614
552 if (expect_false (req->type == EIO_GROUP && req->size)) 615 if (ecb_expect_false (req->type == EIO_GROUP && req->size))
553 { 616 {
554 req->int1 = 1; /* mark request as delayed */ 617 req->int1 = 1; /* mark request as delayed */
555 continue; 618 continue;
556 } 619 }
557 else 620 else
558 { 621 {
559 int res = ETP_FINISH (req); 622 int res = ETP_FINISH (req);
560 if (expect_false (res)) 623 if (ecb_expect_false (res))
561 return res; 624 return res;
562 } 625 }
563 626
564 if (expect_false (maxreqs && !--maxreqs)) 627 if (ecb_expect_false (maxreqs && !--maxreqs))
565 break; 628 break;
566 629
567 if (maxtime) 630 if (maxtime)
568 { 631 {
569 gettimeofday (&tv_now, 0); 632 gettimeofday (&tv_now, 0);
575 638
576 errno = EAGAIN; 639 errno = EAGAIN;
577 return -1; 640 return -1;
578} 641}
579 642
643static void
580static void etp_cancel (ETP_REQ *req) 644etp_cancel (ETP_REQ *req)
581{ 645{
582 X_LOCK (wrklock); 646 req->cancelled = 1;
583 req->flags |= EIO_FLAG_CANCELLED;
584 X_UNLOCK (wrklock);
585 647
586 eio_grp_cancel (req); 648 eio_grp_cancel (req);
587} 649}
588 650
651static void
589static void etp_submit (ETP_REQ *req) 652etp_submit (ETP_REQ *req)
590{ 653{
591 req->pri -= ETP_PRI_MIN; 654 req->pri -= ETP_PRI_MIN;
592 655
593 if (expect_false (req->pri < ETP_PRI_MIN - ETP_PRI_MIN)) req->pri = ETP_PRI_MIN - ETP_PRI_MIN; 656 if (ecb_expect_false (req->pri < ETP_PRI_MIN - ETP_PRI_MIN)) req->pri = ETP_PRI_MIN - ETP_PRI_MIN;
594 if (expect_false (req->pri > ETP_PRI_MAX - ETP_PRI_MIN)) req->pri = ETP_PRI_MAX - ETP_PRI_MIN; 657 if (ecb_expect_false (req->pri > ETP_PRI_MAX - ETP_PRI_MIN)) req->pri = ETP_PRI_MAX - ETP_PRI_MIN;
595 658
596 if (expect_false (req->type == EIO_GROUP)) 659 if (ecb_expect_false (req->type == EIO_GROUP))
597 { 660 {
598 /* I hope this is worth it :/ */ 661 /* I hope this is worth it :/ */
599 X_LOCK (reqlock); 662 X_LOCK (reqlock);
600 ++nreqs; 663 ++nreqs;
601 X_UNLOCK (reqlock); 664 X_UNLOCK (reqlock);
620 683
621 etp_maybe_start_thread (); 684 etp_maybe_start_thread ();
622 } 685 }
623} 686}
624 687
688static void ecb_cold
625static void etp_set_max_poll_time (double nseconds) 689etp_set_max_poll_time (double nseconds)
626{ 690{
627 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 691 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
628 max_poll_time = nseconds * EIO_TICKS; 692 max_poll_time = nseconds * EIO_TICKS;
629 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); 693 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock);
630} 694}
631 695
696static void ecb_cold
632static void etp_set_max_poll_reqs (unsigned int maxreqs) 697etp_set_max_poll_reqs (unsigned int maxreqs)
633{ 698{
634 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 699 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
635 max_poll_reqs = maxreqs; 700 max_poll_reqs = maxreqs;
636 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); 701 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock);
637} 702}
638 703
704static void ecb_cold
639static void etp_set_max_idle (unsigned int nthreads) 705etp_set_max_idle (unsigned int nthreads)
640{ 706{
641 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 707 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
642 max_idle = nthreads; 708 max_idle = nthreads;
643 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 709 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
644} 710}
645 711
712static void ecb_cold
646static void etp_set_idle_timeout (unsigned int seconds) 713etp_set_idle_timeout (unsigned int seconds)
647{ 714{
648 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 715 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
649 idle_timeout = seconds; 716 idle_timeout = seconds;
650 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 717 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
651} 718}
652 719
720static void ecb_cold
653static void etp_set_min_parallel (unsigned int nthreads) 721etp_set_min_parallel (unsigned int nthreads)
654{ 722{
655 if (wanted < nthreads) 723 if (wanted < nthreads)
656 wanted = nthreads; 724 wanted = nthreads;
657} 725}
658 726
727static void ecb_cold
659static void etp_set_max_parallel (unsigned int nthreads) 728etp_set_max_parallel (unsigned int nthreads)
660{ 729{
661 if (wanted > nthreads) 730 if (wanted > nthreads)
662 wanted = nthreads; 731 wanted = nthreads;
663 732
664 while (started > wanted) 733 while (started > wanted)
665 etp_end_thread (); 734 etp_end_thread ();
666} 735}
667 736
668/*****************************************************************************/ 737/*****************************************************************************/
669 738
739static void
670static void grp_try_feed (eio_req *grp) 740grp_try_feed (eio_req *grp)
671{ 741{
672 while (grp->size < grp->int2 && !EIO_CANCELLED (grp)) 742 while (grp->size < grp->int2 && !EIO_CANCELLED (grp))
673 { 743 {
674 grp->flags &= ~EIO_FLAG_GROUPADD; 744 grp->flags &= ~EIO_FLAG_GROUPADD;
675 745
682 break; 752 break;
683 } 753 }
684 } 754 }
685} 755}
686 756
757static int
687static int grp_dec (eio_req *grp) 758grp_dec (eio_req *grp)
688{ 759{
689 --grp->size; 760 --grp->size;
690 761
691 /* call feeder, if applicable */ 762 /* call feeder, if applicable */
692 grp_try_feed (grp); 763 grp_try_feed (grp);
696 return eio_finish (grp); 767 return eio_finish (grp);
697 else 768 else
698 return 0; 769 return 0;
699} 770}
700 771
772static void
701void eio_destroy (eio_req *req) 773eio_destroy (eio_req *req)
702{ 774{
703 if ((req)->flags & EIO_FLAG_PTR1_FREE) free (req->ptr1); 775 if ((req)->flags & EIO_FLAG_PTR1_FREE) free (req->ptr1);
704 if ((req)->flags & EIO_FLAG_PTR2_FREE) free (req->ptr2); 776 if ((req)->flags & EIO_FLAG_PTR2_FREE) free (req->ptr2);
705 777
706 EIO_DESTROY (req); 778 EIO_DESTROY (req);
707} 779}
708 780
781static int
709static int eio_finish (eio_req *req) 782eio_finish (eio_req *req)
710{ 783{
711 int res = EIO_FINISH (req); 784 int res = EIO_FINISH (req);
712 785
713 if (req->grp) 786 if (req->grp)
714 { 787 {
722 if (grp->grp_first == req) 795 if (grp->grp_first == req)
723 grp->grp_first = req->grp_next; 796 grp->grp_first = req->grp_next;
724 797
725 res2 = grp_dec (grp); 798 res2 = grp_dec (grp);
726 799
727 if (!res && res2) 800 if (!res)
728 res = res2; 801 res = res2;
729 } 802 }
730 803
731 eio_destroy (req); 804 eio_destroy (req);
732 805
733 return res; 806 return res;
734} 807}
735 808
809void
736void eio_grp_cancel (eio_req *grp) 810eio_grp_cancel (eio_req *grp)
737{ 811{
738 for (grp = grp->grp_first; grp; grp = grp->grp_next) 812 for (grp = grp->grp_first; grp; grp = grp->grp_next)
739 eio_cancel (grp); 813 eio_cancel (grp);
740} 814}
741 815
816void
742void eio_cancel (eio_req *req) 817eio_cancel (eio_req *req)
743{ 818{
744 etp_cancel (req); 819 etp_cancel (req);
745} 820}
746 821
822void
747void eio_submit (eio_req *req) 823eio_submit (eio_req *req)
748{ 824{
749 etp_submit (req); 825 etp_submit (req);
750} 826}
751 827
752unsigned int eio_nreqs (void) 828unsigned int
829eio_nreqs (void)
753{ 830{
754 return etp_nreqs (); 831 return etp_nreqs ();
755} 832}
756 833
757unsigned int eio_nready (void) 834unsigned int
835eio_nready (void)
758{ 836{
759 return etp_nready (); 837 return etp_nready ();
760} 838}
761 839
762unsigned int eio_npending (void) 840unsigned int
841eio_npending (void)
763{ 842{
764 return etp_npending (); 843 return etp_npending ();
765} 844}
766 845
767unsigned int eio_nthreads (void) 846unsigned int ecb_cold
847eio_nthreads (void)
768{ 848{
769 return etp_nthreads (); 849 return etp_nthreads ();
770} 850}
771 851
852void ecb_cold
772void eio_set_max_poll_time (double nseconds) 853eio_set_max_poll_time (double nseconds)
773{ 854{
774 etp_set_max_poll_time (nseconds); 855 etp_set_max_poll_time (nseconds);
775} 856}
776 857
858void ecb_cold
777void eio_set_max_poll_reqs (unsigned int maxreqs) 859eio_set_max_poll_reqs (unsigned int maxreqs)
778{ 860{
779 etp_set_max_poll_reqs (maxreqs); 861 etp_set_max_poll_reqs (maxreqs);
780} 862}
781 863
864void ecb_cold
782void eio_set_max_idle (unsigned int nthreads) 865eio_set_max_idle (unsigned int nthreads)
783{ 866{
784 etp_set_max_idle (nthreads); 867 etp_set_max_idle (nthreads);
785} 868}
786 869
870void ecb_cold
787void eio_set_idle_timeout (unsigned int seconds) 871eio_set_idle_timeout (unsigned int seconds)
788{ 872{
789 etp_set_idle_timeout (seconds); 873 etp_set_idle_timeout (seconds);
790} 874}
791 875
876void ecb_cold
792void eio_set_min_parallel (unsigned int nthreads) 877eio_set_min_parallel (unsigned int nthreads)
793{ 878{
794 etp_set_min_parallel (nthreads); 879 etp_set_min_parallel (nthreads);
795} 880}
796 881
882void ecb_cold
797void eio_set_max_parallel (unsigned int nthreads) 883eio_set_max_parallel (unsigned int nthreads)
798{ 884{
799 etp_set_max_parallel (nthreads); 885 etp_set_max_parallel (nthreads);
800} 886}
801 887
802int eio_poll (void) 888int eio_poll (void)
811# undef pread 897# undef pread
812# undef pwrite 898# undef pwrite
813# define pread eio__pread 899# define pread eio__pread
814# define pwrite eio__pwrite 900# define pwrite eio__pwrite
815 901
816static ssize_t 902static eio_ssize_t
817eio__pread (int fd, void *buf, size_t count, off_t offset) 903eio__pread (int fd, void *buf, size_t count, off_t offset)
818{ 904{
819 ssize_t res; 905 eio_ssize_t res;
820 off_t ooffset; 906 off_t ooffset;
821 907
822 X_LOCK (preadwritelock); 908 X_LOCK (preadwritelock);
823 ooffset = lseek (fd, 0, SEEK_CUR); 909 ooffset = lseek (fd, 0, SEEK_CUR);
824 lseek (fd, offset, SEEK_SET); 910 lseek (fd, offset, SEEK_SET);
827 X_UNLOCK (preadwritelock); 913 X_UNLOCK (preadwritelock);
828 914
829 return res; 915 return res;
830} 916}
831 917
832static ssize_t 918static eio_ssize_t
833eio__pwrite (int fd, void *buf, size_t count, off_t offset) 919eio__pwrite (int fd, void *buf, size_t count, off_t offset)
834{ 920{
835 ssize_t res; 921 eio_ssize_t res;
836 off_t ooffset; 922 off_t ooffset;
837 923
838 X_LOCK (preadwritelock); 924 X_LOCK (preadwritelock);
839 ooffset = lseek (fd, 0, SEEK_CUR); 925 ooffset = lseek (fd, 0, SEEK_CUR);
840 lseek (fd, offset, SEEK_SET); 926 lseek (fd, offset, SEEK_SET);
872#ifndef HAVE_FUTIMES 958#ifndef HAVE_FUTIMES
873 959
874# undef futimes 960# undef futimes
875# define futimes(fd,times) eio__futimes (fd, times) 961# define futimes(fd,times) eio__futimes (fd, times)
876 962
963static int
877static int eio__futimes (int fd, const struct timeval tv[2]) 964eio__futimes (int fd, const struct timeval tv[2])
878{ 965{
879 errno = ENOSYS; 966 errno = ENOSYS;
880 return -1; 967 return -1;
881} 968}
882 969
886# undef fdatasync 973# undef fdatasync
887# define fdatasync(fd) fsync (fd) 974# define fdatasync(fd) fsync (fd)
888#endif 975#endif
889 976
890/* sync_file_range always needs emulation */ 977/* sync_file_range always needs emulation */
891int 978static int
892eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags) 979eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags)
893{ 980{
894#if HAVE_SYNC_FILE_RANGE 981#if HAVE_SYNC_FILE_RANGE
895 int res; 982 int res;
896 983
913 /* even though we could play tricks with the flags, it's better to always 1000 /* even though we could play tricks with the flags, it's better to always
914 * call fdatasync, as that matches the expectation of its users best */ 1001 * call fdatasync, as that matches the expectation of its users best */
915 return fdatasync (fd); 1002 return fdatasync (fd);
916} 1003}
917 1004
1005static int
1006eio__fallocate (int fd, int mode, off_t offset, size_t len)
1007{
1008#if HAVE_FALLOCATE
1009 return fallocate (fd, mode, offset, len);
1010#else
1011 errno = ENOSYS;
1012 return -1;
1013#endif
1014}
1015
918#if !HAVE_READAHEAD 1016#if !HAVE_READAHEAD
919# undef readahead 1017# undef readahead
920# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) 1018# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self)
921 1019
922static ssize_t 1020static eio_ssize_t
923eio__readahead (int fd, off_t offset, size_t count, etp_worker *self) 1021eio__readahead (int fd, off_t offset, size_t count, etp_worker *self)
924{ 1022{
925 size_t todo = count; 1023 size_t todo = count;
926 dBUF; 1024 dBUF;
927 1025
939} 1037}
940 1038
941#endif 1039#endif
942 1040
943/* sendfile always needs emulation */ 1041/* sendfile always needs emulation */
944static ssize_t 1042static eio_ssize_t
945eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) 1043eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self)
946{ 1044{
1045 eio_ssize_t written = 0;
947 ssize_t res; 1046 eio_ssize_t res;
948 1047
949 if (!count) 1048 if (!count)
950 return 0; 1049 return 0;
951 1050
1051 for (;;)
1052 {
1053#ifdef __APPLE__
1054# undef HAVE_SENDFILE /* broken, as everything on os x */
1055#endif
952#if HAVE_SENDFILE 1056#if HAVE_SENDFILE
953# if __linux 1057# if __linux
1058 off_t soffset = offset;
954 res = sendfile (ofd, ifd, &offset, count); 1059 res = sendfile (ofd, ifd, &soffset, count);
955 1060
956# elif __FreeBSD__ 1061# elif __FreeBSD__
957 /* 1062 /*
958 * Of course, the freebsd sendfile is a dire hack with no thoughts 1063 * Of course, the freebsd sendfile is a dire hack with no thoughts
959 * wasted on making it similar to other I/O functions. 1064 * wasted on making it similar to other I/O functions.
960 */ 1065 */
961 {
962 off_t sbytes; 1066 off_t sbytes;
963 res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); 1067 res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0);
964 1068
965 #if 0 /* according to the manpage, this is correct, but broken behaviour */ 1069 #if 0 /* according to the manpage, this is correct, but broken behaviour */
966 /* freebsd' sendfile will return 0 on success */ 1070 /* freebsd' sendfile will return 0 on success */
967 /* freebsd 8 documents it as only setting *sbytes on EINTR and EAGAIN, but */ 1071 /* freebsd 8 documents it as only setting *sbytes on EINTR and EAGAIN, but */
968 /* not on e.g. EIO or EPIPE - sounds broken */ 1072 /* not on e.g. EIO or EPIPE - sounds broken */
969 if ((res < 0 && (errno == EAGAIN || errno == EINTR) && sbytes) || res == 0) 1073 if ((res < 0 && (errno == EAGAIN || errno == EINTR) && sbytes) || res == 0)
970 res = sbytes; 1074 res = sbytes;
971 #endif 1075 #endif
972 1076
973 /* according to source inspection, this is correct, and useful behaviour */ 1077 /* according to source inspection, this is correct, and useful behaviour */
974 if (sbytes) 1078 if (sbytes)
975 res = sbytes; 1079 res = sbytes;
976 }
977 1080
978# elif defined (__APPLE__) 1081# elif defined (__APPLE__)
979
980 {
981 off_t sbytes = count; 1082 off_t sbytes = count;
982 res = sendfile (ifd, ofd, offset, &sbytes, 0, 0); 1083 res = sendfile (ifd, ofd, offset, &sbytes, 0, 0);
983 1084
984 /* according to the manpage, sbytes is always valid */ 1085 /* according to the manpage, sbytes is always valid */
985 if (sbytes) 1086 if (sbytes)
986 res = sbytes; 1087 res = sbytes;
987 }
988 1088
989# elif __hpux 1089# elif __hpux
990 res = sendfile (ofd, ifd, offset, count, 0, 0); 1090 res = sendfile (ofd, ifd, offset, count, 0, 0);
991 1091
992# elif __solaris 1092# elif __solaris
993 {
994 struct sendfilevec vec; 1093 struct sendfilevec vec;
995 size_t sbytes; 1094 size_t sbytes;
996 1095
997 vec.sfv_fd = ifd; 1096 vec.sfv_fd = ifd;
998 vec.sfv_flag = 0; 1097 vec.sfv_flag = 0;
999 vec.sfv_off = offset; 1098 vec.sfv_off = offset;
1000 vec.sfv_len = count; 1099 vec.sfv_len = count;
1001 1100
1002 res = sendfilev (ofd, &vec, 1, &sbytes); 1101 res = sendfilev (ofd, &vec, 1, &sbytes);
1003 1102
1004 if (res < 0 && sbytes) 1103 if (res < 0 && sbytes)
1005 res = sbytes; 1104 res = sbytes;
1006 }
1007 1105
1008# endif 1106# endif
1009 1107
1010#elif defined (_WIN32) 1108#elif defined (_WIN32) && 0
1011
1012 /* does not work, just for documentation of what would need to be done */ 1109 /* does not work, just for documentation of what would need to be done */
1013 { 1110 /* actually, cannot be done like this, as TransmitFile changes the file offset, */
1111 /* libeio guarantees that the file offset does not change, and windows */
1112 /* has no way to get an independent handle to the same file description */
1014 HANDLE h = TO_SOCKET (ifd); 1113 HANDLE h = TO_SOCKET (ifd);
1015 SetFilePointer (h, offset, 0, FILE_BEGIN); 1114 SetFilePointer (h, offset, 0, FILE_BEGIN);
1016 res = TransmitFile (TO_SOCKET (ofd), h, count, 0, 0, 0, 0); 1115 res = TransmitFile (TO_SOCKET (ofd), h, count, 0, 0, 0, 0);
1017 }
1018 1116
1019#else 1117#else
1020 res = -1; 1118 res = -1;
1021 errno = ENOSYS; 1119 errno = ENOSYS;
1022#endif 1120#endif
1023 1121
1122 /* we assume sendfile can copy at least 128mb in one go */
1123 if (res <= 128 * 1024 * 1024)
1124 {
1125 if (res > 0)
1126 written += res;
1127
1128 if (written)
1129 return written;
1130
1131 break;
1132 }
1133 else
1134 {
1135 /* if we requested more, then probably the kernel was lazy */
1136 written += res;
1137 offset += res;
1138 count -= res;
1139
1140 if (!count)
1141 return written;
1142 }
1143 }
1144
1024 if (res < 0 1145 if (res < 0
1025 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK 1146 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK
1026 /* BSDs */ 1147 /* BSDs */
1027#ifdef ENOTSUP /* sigh, if the steenking pile called openbsd would only try to at least compile posix code... */ 1148#ifdef ENOTSUP /* sigh, if the steenking pile called openbsd would only try to at least compile posix code... */
1028 || errno == ENOTSUP 1149 || errno == ENOTSUP
1029#endif 1150#endif
1151#ifdef EOPNOTSUPP /* windows */
1030 || errno == EOPNOTSUPP /* BSDs */ 1152 || errno == EOPNOTSUPP /* BSDs */
1153#endif
1031#if __solaris 1154#if __solaris
1032 || errno == EAFNOSUPPORT || errno == EPROTOTYPE 1155 || errno == EAFNOSUPPORT || errno == EPROTOTYPE
1033#endif 1156#endif
1034 ) 1157 )
1035 ) 1158 )
1039 1162
1040 res = 0; 1163 res = 0;
1041 1164
1042 while (count) 1165 while (count)
1043 { 1166 {
1044 ssize_t cnt; 1167 eio_ssize_t cnt;
1045 1168
1046 cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset); 1169 cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset);
1047 1170
1048 if (cnt <= 0) 1171 if (cnt <= 0)
1049 { 1172 {
1064 count -= cnt; 1187 count -= cnt;
1065 } 1188 }
1066 } 1189 }
1067 1190
1068 return res; 1191 return res;
1192}
1193
1194#ifdef PAGESIZE
1195# define eio_pagesize() PAGESIZE
1196#else
1197static intptr_t
1198eio_pagesize (void)
1199{
1200 static intptr_t page;
1201
1202 if (!page)
1203 page = sysconf (_SC_PAGESIZE);
1204
1205 return page;
1206}
1207#endif
1208
1209static void
1210eio_page_align (void **addr, size_t *length)
1211{
1212 intptr_t mask = eio_pagesize () - 1;
1213
1214 /* round down addr */
1215 intptr_t adj = mask & (intptr_t)*addr;
1216
1217 *addr = (void *)((intptr_t)*addr - adj);
1218 *length += adj;
1219
1220 /* round up length */
1221 *length = (*length + mask) & ~mask;
1222}
1223
1224#if !_POSIX_MEMLOCK
1225# define eio__mlockall(a) EIO_ENOSYS ()
1226#else
1227
1228static int
1229eio__mlockall (int flags)
1230{
1231 #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7
1232 extern int mallopt (int, int);
1233 mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */
1234 #endif
1235
1236 if (EIO_MCL_CURRENT != MCL_CURRENT
1237 || EIO_MCL_FUTURE != MCL_FUTURE)
1238 {
1239 flags = 0
1240 | (flags & EIO_MCL_CURRENT ? MCL_CURRENT : 0)
1241 | (flags & EIO_MCL_FUTURE ? MCL_FUTURE : 0);
1242 }
1243
1244 return mlockall (flags);
1245}
1246#endif
1247
1248#if !_POSIX_MEMLOCK_RANGE
1249# define eio__mlock(a,b) EIO_ENOSYS ()
1250#else
1251
1252static int
1253eio__mlock (void *addr, size_t length)
1254{
1255 eio_page_align (&addr, &length);
1256
1257 return mlock (addr, length);
1258}
1259
1260#endif
1261
1262#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO)
1263# define eio__msync(a,b,c) EIO_ENOSYS ()
1264#else
1265
1266static int
1267eio__msync (void *mem, size_t len, int flags)
1268{
1269 eio_page_align (&mem, &len);
1270
1271 if (EIO_MS_ASYNC != MS_SYNC
1272 || EIO_MS_INVALIDATE != MS_INVALIDATE
1273 || EIO_MS_SYNC != MS_SYNC)
1274 {
1275 flags = 0
1276 | (flags & EIO_MS_ASYNC ? MS_ASYNC : 0)
1277 | (flags & EIO_MS_INVALIDATE ? MS_INVALIDATE : 0)
1278 | (flags & EIO_MS_SYNC ? MS_SYNC : 0);
1279 }
1280
1281 return msync (mem, len, flags);
1282}
1283
1284#endif
1285
1286static int
1287eio__mtouch (eio_req *req)
1288{
1289 void *mem = req->ptr2;
1290 size_t len = req->size;
1291 int flags = req->int1;
1292
1293 eio_page_align (&mem, &len);
1294
1295 {
1296 intptr_t addr = (intptr_t)mem;
1297 intptr_t end = addr + len;
1298 intptr_t page = eio_pagesize ();
1299
1300 if (addr < end)
1301 if (flags & EIO_MT_MODIFY) /* modify */
1302 do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req));
1303 else
1304 do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req));
1305 }
1306
1307 return 0;
1308}
1309
1310/*****************************************************************************/
1311/* requests implemented outside eio_execute, because they are so large */
1312
1313static void
1314eio__realpath (eio_req *req, etp_worker *self)
1315{
1316 char *rel = req->ptr1;
1317 char *res;
1318 char *tmp1, *tmp2;
1319#if SYMLOOP_MAX > 32
1320 int symlinks = SYMLOOP_MAX;
1321#else
1322 int symlinks = 32;
1323#endif
1324
1325 req->result = -1;
1326
1327 errno = EINVAL;
1328 if (!rel)
1329 return;
1330
1331 errno = ENOENT;
1332 if (!*rel)
1333 return;
1334
1335 if (!req->ptr2)
1336 {
1337 X_LOCK (wrklock);
1338 req->flags |= EIO_FLAG_PTR2_FREE;
1339 X_UNLOCK (wrklock);
1340 req->ptr2 = malloc (PATH_MAX * 3);
1341
1342 errno = ENOMEM;
1343 if (!req->ptr2)
1344 return;
1345 }
1346
1347 res = req->ptr2;
1348 tmp1 = res + PATH_MAX;
1349 tmp2 = tmp1 + PATH_MAX;
1350
1351#if 0 /* disabled, the musl way to do things is just too racy */
1352#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME)
1353 /* on linux we may be able to ask the kernel */
1354 {
1355 int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME);
1356
1357 if (fd >= 0)
1358 {
1359 sprintf (tmp1, "/proc/self/fd/%d", fd);
1360 req->result = readlink (tmp1, res, PATH_MAX);
1361 close (fd);
1362
1363 /* here we should probably stat the open file and the disk file, to make sure they still match */
1364
1365 if (req->result > 0)
1366 goto done;
1367 }
1368 else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO)
1369 return;
1370 }
1371#endif
1372#endif
1373
1374 if (*rel != '/')
1375 {
1376 if (!getcwd (res, PATH_MAX))
1377 return;
1378
1379 if (res [1]) /* only use if not / */
1380 res += strlen (res);
1381 }
1382
1383 while (*rel)
1384 {
1385 eio_ssize_t len, linklen;
1386 char *beg = rel;
1387
1388 while (*rel && *rel != '/')
1389 ++rel;
1390
1391 len = rel - beg;
1392
1393 if (!len) /* skip slashes */
1394 {
1395 ++rel;
1396 continue;
1397 }
1398
1399 if (beg [0] == '.')
1400 {
1401 if (len == 1)
1402 continue; /* . - nop */
1403
1404 if (beg [1] == '.' && len == 2)
1405 {
1406 /* .. - back up one component, if possible */
1407
1408 while (res != req->ptr2)
1409 if (*--res == '/')
1410 break;
1411
1412 continue;
1413 }
1414 }
1415
1416 errno = ENAMETOOLONG;
1417 if (res + 1 + len + 1 >= tmp1)
1418 return;
1419
1420 /* copy one component */
1421 *res = '/';
1422 memcpy (res + 1, beg, len);
1423
1424 /* zero-terminate, for readlink */
1425 res [len + 1] = 0;
1426
1427 /* now check if it's a symlink */
1428 linklen = readlink (req->ptr2, tmp1, PATH_MAX);
1429
1430 if (linklen < 0)
1431 {
1432 if (errno != EINVAL)
1433 return;
1434
1435 /* it's a normal directory. hopefully */
1436 res += len + 1;
1437 }
1438 else
1439 {
1440 /* yay, it was a symlink - build new path in tmp2 */
1441 int rellen = strlen (rel);
1442
1443 errno = ENAMETOOLONG;
1444 if (linklen + 1 + rellen >= PATH_MAX)
1445 return;
1446
1447 errno = ELOOP;
1448 if (!--symlinks)
1449 return;
1450
1451 if (*tmp1 == '/')
1452 res = req->ptr2; /* symlink resolves to an absolute path */
1453
1454 /* we need to be careful, as rel might point into tmp2 already */
1455 memmove (tmp2 + linklen + 1, rel, rellen + 1);
1456 tmp2 [linklen] = '/';
1457 memcpy (tmp2, tmp1, linklen);
1458
1459 rel = tmp2;
1460 }
1461 }
1462
1463 /* special case for the lone root path */
1464 if (res == req->ptr2)
1465 *res++ = '/';
1466
1467 req->result = res - (char *)req->ptr2;
1468
1469done:
1470 req->ptr2 = realloc (req->ptr2, req->result); /* trade time for space savings */
1069} 1471}
1070 1472
1071static signed char 1473static signed char
1072eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) 1474eio_dent_cmp (const eio_dirent *a, const eio_dirent *b)
1073{ 1475{
1255 1657
1256 X_LOCK (wrklock); 1658 X_LOCK (wrklock);
1257 /* the corresponding closedir is in ETP_WORKER_CLEAR */ 1659 /* the corresponding closedir is in ETP_WORKER_CLEAR */
1258 self->dirp = dirp = opendir (req->ptr1); 1660 self->dirp = dirp = opendir (req->ptr1);
1259 1661
1662 if (req->flags & EIO_FLAG_PTR1_FREE)
1663 free (req->ptr1);
1664
1260 req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; 1665 req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE;
1261 req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; 1666 req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0;
1262 req->ptr2 = names = malloc (namesalloc); 1667 req->ptr2 = names = malloc (namesalloc);
1263 X_UNLOCK (wrklock); 1668 X_UNLOCK (wrklock);
1264 1669
1315 /* skip . and .. entries */ 1720 /* skip . and .. entries */
1316 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) 1721 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2])))
1317 { 1722 {
1318 int len = D_NAMLEN (entp) + 1; 1723 int len = D_NAMLEN (entp) + 1;
1319 1724
1320 while (expect_false (namesoffs + len > namesalloc)) 1725 while (ecb_expect_false (namesoffs + len > namesalloc))
1321 { 1726 {
1322 namesalloc *= 2; 1727 namesalloc *= 2;
1323 X_LOCK (wrklock); 1728 X_LOCK (wrklock);
1324 req->ptr2 = names = realloc (names, namesalloc); 1729 req->ptr2 = names = realloc (names, namesalloc);
1325 X_UNLOCK (wrklock); 1730 X_UNLOCK (wrklock);
1332 1737
1333 if (dents) 1738 if (dents)
1334 { 1739 {
1335 struct eio_dirent *ent; 1740 struct eio_dirent *ent;
1336 1741
1337 if (expect_false (dentoffs == dentalloc)) 1742 if (ecb_expect_false (dentoffs == dentalloc))
1338 { 1743 {
1339 dentalloc *= 2; 1744 dentalloc *= 2;
1340 X_LOCK (wrklock); 1745 X_LOCK (wrklock);
1341 req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent)); 1746 req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent));
1342 X_UNLOCK (wrklock); 1747 X_UNLOCK (wrklock);
1430 break; 1835 break;
1431 } 1836 }
1432 } 1837 }
1433} 1838}
1434 1839
1435#ifdef PAGESIZE
1436# define eio_pagesize() PAGESIZE
1437#else
1438static intptr_t
1439eio_pagesize (void)
1440{
1441 static intptr_t page;
1442
1443 if (!page)
1444 page = sysconf (_SC_PAGESIZE);
1445
1446 return page;
1447}
1448#endif
1449
1450static void
1451eio_page_align (void **addr, size_t *length)
1452{
1453 intptr_t mask = eio_pagesize () - 1;
1454
1455 /* round down addr */
1456 intptr_t adj = mask & (intptr_t)*addr;
1457
1458 *addr = (void *)((intptr_t)*addr - adj);
1459 *length += adj;
1460
1461 /* round up length */
1462 *length = (*length + mask) & ~mask;
1463}
1464
1465#if !_POSIX_MEMLOCK
1466# define eio__mlockall(a) ((errno = ENOSYS), -1)
1467#else
1468
1469static int
1470eio__mlockall (int flags)
1471{
1472 #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7
1473 extern int mallopt (int, int);
1474 mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */
1475 #endif
1476
1477 if (EIO_MCL_CURRENT != MCL_CURRENT
1478 || EIO_MCL_FUTURE != MCL_FUTURE)
1479 {
1480 flags = 0
1481 | (flags & EIO_MCL_CURRENT ? MCL_CURRENT : 0)
1482 | (flags & EIO_MCL_FUTURE ? MCL_FUTURE : 0);
1483 }
1484
1485 return mlockall (flags);
1486}
1487#endif
1488
1489#if !_POSIX_MEMLOCK_RANGE
1490# define eio__mlock(a,b) ((errno = ENOSYS), -1)
1491#else
1492
1493static int
1494eio__mlock (void *addr, size_t length)
1495{
1496 eio_page_align (&addr, &length);
1497
1498 return mlock (addr, length);
1499}
1500
1501#endif
1502
1503#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO)
1504# define eio__msync(a,b,c) ((errno = ENOSYS), -1)
1505#else
1506
1507int
1508eio__msync (void *mem, size_t len, int flags)
1509{
1510 eio_page_align (&mem, &len);
1511
1512 if (EIO_MS_ASYNC != MS_SYNC
1513 || EIO_MS_INVALIDATE != MS_INVALIDATE
1514 || EIO_MS_SYNC != MS_SYNC)
1515 {
1516 flags = 0
1517 | (flags & EIO_MS_ASYNC ? MS_ASYNC : 0)
1518 | (flags & EIO_MS_INVALIDATE ? MS_INVALIDATE : 0)
1519 | (flags & EIO_MS_SYNC ? MS_SYNC : 0);
1520 }
1521
1522 return msync (mem, len, flags);
1523}
1524
1525#endif
1526
1527int
1528eio__mtouch (void *mem, size_t len, int flags)
1529{
1530 eio_page_align (&mem, &len);
1531
1532 {
1533 intptr_t addr = (intptr_t)mem;
1534 intptr_t end = addr + len;
1535 intptr_t page = eio_pagesize ();
1536
1537 if (addr < end)
1538 if (flags & EIO_MT_MODIFY) /* modify */
1539 do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len);
1540 else
1541 do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len);
1542 }
1543
1544 return 0;
1545}
1546
1547/*****************************************************************************/ 1840/*****************************************************************************/
1548 1841
1549#define ALLOC(len) \ 1842#define ALLOC(len) \
1550 if (!req->ptr2) \ 1843 if (!req->ptr2) \
1551 { \ 1844 { \
1564X_THREAD_PROC (etp_proc) 1857X_THREAD_PROC (etp_proc)
1565{ 1858{
1566 ETP_REQ *req; 1859 ETP_REQ *req;
1567 struct timespec ts; 1860 struct timespec ts;
1568 etp_worker *self = (etp_worker *)thr_arg; 1861 etp_worker *self = (etp_worker *)thr_arg;
1862 int timeout;
1569 1863
1570 /* try to distribute timeouts somewhat randomly */ 1864 /* try to distribute timeouts somewhat evenly */
1571 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 1865 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
1572 1866
1573 for (;;) 1867 for (;;)
1574 { 1868 {
1869 ts.tv_sec = 0;
1870
1575 X_LOCK (reqlock); 1871 X_LOCK (reqlock);
1576 1872
1577 for (;;) 1873 for (;;)
1578 { 1874 {
1579 self->req = req = reqq_shift (&req_queue); 1875 self->req = req = reqq_shift (&req_queue);
1580 1876
1581 if (req) 1877 if (req)
1582 break; 1878 break;
1583 1879
1880 if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */
1881 {
1882 X_UNLOCK (reqlock);
1883 X_LOCK (wrklock);
1884 --started;
1885 X_UNLOCK (wrklock);
1886 goto quit;
1887 }
1888
1584 ++idle; 1889 ++idle;
1585 1890
1586 ts.tv_sec = time (0) + idle_timeout; 1891 if (idle <= max_idle)
1587 if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT) 1892 /* we are allowed to idle, so do so without any timeout */
1893 X_COND_WAIT (reqwait, reqlock);
1894 else
1588 { 1895 {
1589 if (idle > max_idle) 1896 /* initialise timeout once */
1590 { 1897 if (!ts.tv_sec)
1591 --idle; 1898 ts.tv_sec = time (0) + idle_timeout;
1592 X_UNLOCK (reqlock);
1593 X_LOCK (wrklock);
1594 --started;
1595 X_UNLOCK (wrklock);
1596 goto quit;
1597 }
1598 1899
1599 /* we are allowed to idle, so do so without any timeout */
1600 X_COND_WAIT (reqwait, reqlock); 1900 if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT)
1901 ts.tv_sec = 1; /* assuming this is not a value computed above.,.. */
1601 } 1902 }
1602 1903
1603 --idle; 1904 --idle;
1604 } 1905 }
1605 1906
1608 X_UNLOCK (reqlock); 1909 X_UNLOCK (reqlock);
1609 1910
1610 if (req->type < 0) 1911 if (req->type < 0)
1611 goto quit; 1912 goto quit;
1612 1913
1613 if (!EIO_CANCELLED (req))
1614 ETP_EXECUTE (self, req); 1914 ETP_EXECUTE (self, req);
1615 1915
1616 X_LOCK (reslock); 1916 X_LOCK (reslock);
1617 1917
1618 ++npending; 1918 ++npending;
1619 1919
1634 return 0; 1934 return 0;
1635} 1935}
1636 1936
1637/*****************************************************************************/ 1937/*****************************************************************************/
1638 1938
1939int ecb_cold
1639int eio_init (void (*want_poll)(void), void (*done_poll)(void)) 1940eio_init (void (*want_poll)(void), void (*done_poll)(void))
1640{ 1941{
1641 return etp_init (want_poll, done_poll); 1942 return etp_init (want_poll, done_poll);
1642} 1943}
1643 1944
1945ecb_inline void
1644static void eio_api_destroy (eio_req *req) 1946eio_api_destroy (eio_req *req)
1645{ 1947{
1646 free (req); 1948 free (req);
1647} 1949}
1648 1950
1649#define REQ(rtype) \ 1951#define REQ(rtype) \
1668 { \ 1970 { \
1669 eio_api_destroy (req); \ 1971 eio_api_destroy (req); \
1670 return 0; \ 1972 return 0; \
1671 } 1973 }
1672 1974
1975static void
1673static void eio_execute (etp_worker *self, eio_req *req) 1976eio_execute (etp_worker *self, eio_req *req)
1674{ 1977{
1978 if (ecb_expect_false (EIO_CANCELLED (req)))
1979 {
1980 req->result = -1;
1981 req->errorno = ECANCELED;
1982 return;
1983 }
1984
1675 switch (req->type) 1985 switch (req->type)
1676 { 1986 {
1677 case EIO_READ: ALLOC (req->size); 1987 case EIO_READ: ALLOC (req->size);
1678 req->result = req->offs >= 0 1988 req->result = req->offs >= 0
1679 ? pread (req->int1, req->ptr2, req->size, req->offs) 1989 ? pread (req->int1, req->ptr2, req->size, req->offs)
1713 case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break; 2023 case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break;
1714 case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break; 2024 case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break;
1715 case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; 2025 case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break;
1716 case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; 2026 case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break;
1717 2027
2028 case EIO_REALPATH: eio__realpath (req, self); break;
2029
1718 case EIO_READLINK: ALLOC (PATH_MAX); 2030 case EIO_READLINK: ALLOC (PATH_MAX);
1719 req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; 2031 req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break;
1720 2032
1721 case EIO_SYNC: req->result = 0; sync (); break; 2033 case EIO_SYNC: req->result = 0; sync (); break;
1722 case EIO_FSYNC: req->result = fsync (req->int1); break; 2034 case EIO_FSYNC: req->result = fsync (req->int1); break;
1723 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; 2035 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break;
1724 case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; 2036 case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break;
1725 case EIO_MTOUCH: req->result = eio__mtouch (req->ptr2, req->size, req->int1); break; 2037 case EIO_MTOUCH: req->result = eio__mtouch (req); break;
1726 case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; 2038 case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break;
1727 case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; 2039 case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break;
1728 case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; 2040 case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break;
2041 case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break;
1729 2042
1730 case EIO_READDIR: eio__scandir (req, self); break; 2043 case EIO_READDIR: eio__scandir (req, self); break;
1731 2044
1732 case EIO_BUSY: 2045 case EIO_BUSY:
1733#ifdef _WIN32 2046#ifdef _WIN32
1774 case EIO_NOP: 2087 case EIO_NOP:
1775 req->result = 0; 2088 req->result = 0;
1776 break; 2089 break;
1777 2090
1778 case EIO_CUSTOM: 2091 case EIO_CUSTOM:
1779 ((void (*)(eio_req *))req->feed) (req); 2092 req->feed (req);
1780 break; 2093 break;
1781 2094
1782 default: 2095 default:
1783 errno = ENOSYS; 2096 errno = ENOSYS;
1784 req->result = -1; 2097 req->result = -1;
1833eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) 2146eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data)
1834{ 2147{
1835 REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; 2148 REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND;
1836} 2149}
1837 2150
2151eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data)
2152{
2153 REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND;
2154}
2155
1838eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) 2156eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data)
1839{ 2157{
1840 REQ (EIO_FDATASYNC); req->int1 = fd; SEND; 2158 REQ (EIO_FDATASYNC); req->int1 = fd; SEND;
1841} 2159}
1842 2160
1883eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) 2201eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data)
1884{ 2202{
1885 REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; 2203 REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND;
1886} 2204}
1887 2205
1888eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) 2206eio_req *eio_fchown (int fd, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data)
1889{ 2207{
1890 REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND; 2208 REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND;
1891} 2209}
1892 2210
1893eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) 2211eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data)
1913eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) 2231eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data)
1914{ 2232{
1915 REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; 2233 REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND;
1916} 2234}
1917 2235
1918eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) 2236eio_req *eio_chown (const char *path, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data)
1919{ 2237{
1920 REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND; 2238 REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND;
1921} 2239}
1922 2240
1923eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) 2241eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data)
1937} 2255}
1938 2256
1939eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data) 2257eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data)
1940{ 2258{
1941 return eio__1path (EIO_READLINK, path, pri, cb, data); 2259 return eio__1path (EIO_READLINK, path, pri, cb, data);
2260}
2261
2262eio_req *eio_realpath (const char *path, int pri, eio_cb cb, void *data)
2263{
2264 return eio__1path (EIO_REALPATH, path, pri, cb, data);
1942} 2265}
1943 2266
1944eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data) 2267eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data)
1945{ 2268{
1946 return eio__1path (EIO_STAT, path, pri, cb, data); 2269 return eio__1path (EIO_STAT, path, pri, cb, data);
2005eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) 2328eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data)
2006{ 2329{
2007 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); 2330 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data);
2008} 2331}
2009 2332
2010eio_req *eio_custom (eio_cb execute, int pri, eio_cb cb, void *data) 2333eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data)
2011{ 2334{
2012 REQ (EIO_CUSTOM); req->feed = (void (*)(eio_req *))execute; SEND; 2335 REQ (EIO_CUSTOM); req->feed = execute; SEND;
2013} 2336}
2014 2337
2015#endif 2338#endif
2016 2339
2017eio_req *eio_grp (eio_cb cb, void *data) 2340eio_req *eio_grp (eio_cb cb, void *data)
2026#undef SEND 2349#undef SEND
2027 2350
2028/*****************************************************************************/ 2351/*****************************************************************************/
2029/* grp functions */ 2352/* grp functions */
2030 2353
2354void
2031void eio_grp_feed (eio_req *grp, void (*feed)(eio_req *req), int limit) 2355eio_grp_feed (eio_req *grp, void (*feed)(eio_req *req), int limit)
2032{ 2356{
2033 grp->int2 = limit; 2357 grp->int2 = limit;
2034 grp->feed = feed; 2358 grp->feed = feed;
2035 2359
2036 grp_try_feed (grp); 2360 grp_try_feed (grp);
2037} 2361}
2038 2362
2363void
2039void eio_grp_limit (eio_req *grp, int limit) 2364eio_grp_limit (eio_req *grp, int limit)
2040{ 2365{
2041 grp->int2 = limit; 2366 grp->int2 = limit;
2042 2367
2043 grp_try_feed (grp); 2368 grp_try_feed (grp);
2044} 2369}
2045 2370
2371void
2046void eio_grp_add (eio_req *grp, eio_req *req) 2372eio_grp_add (eio_req *grp, eio_req *req)
2047{ 2373{
2048 assert (("cannot add requests to IO::AIO::GRP after the group finished", grp->int1 != 2)); 2374 assert (("cannot add requests to IO::AIO::GRP after the group finished", grp->int1 != 2));
2049 2375
2050 grp->flags |= EIO_FLAG_GROUPADD; 2376 grp->flags |= EIO_FLAG_GROUPADD;
2051 2377
2062} 2388}
2063 2389
2064/*****************************************************************************/ 2390/*****************************************************************************/
2065/* misc garbage */ 2391/* misc garbage */
2066 2392
2393eio_ssize_t
2067ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) 2394eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count)
2068{ 2395{
2069 etp_worker wrk; 2396 etp_worker wrk;
2070 ssize_t ret; 2397 eio_ssize_t ret;
2071 2398
2072 wrk.dbuf = 0; 2399 wrk.dbuf = 0;
2073 2400
2074 ret = eio__sendfile (ofd, ifd, offset, count, &wrk); 2401 ret = eio__sendfile (ofd, ifd, offset, count, &wrk);
2075 2402

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines