--- IO-AIO/AIO.xs 2012/04/07 00:50:33 1.211 +++ IO-AIO/AIO.xs 2012/07/27 17:54:40 1.218 @@ -24,6 +24,7 @@ #if __linux__ # include # ifdef FS_IOC_FIEMAP +# include # include # define HAVE_FIEMAP 1 # endif @@ -168,9 +169,9 @@ #if HAVE_FIEMAP int count = req->int3; - /* heuristic: first try with 64 extents if we don't know how many, */ + /* heuristic: first try with 72 extents if we don't know how many, */ /* as most files have (hopefully) fewer than this many extents */ - /* in fact, most should have <= 2, so maybe the 72 below is probably overkill */ + /* in fact, most should have <= 2, so the 72 below is probably overkill */ if (count < 0) count = 72; /* for what it's worth, 72 extents fit nicely into 4kb */ @@ -195,6 +196,9 @@ if (req->int3 >= 0) break; /* when not autosizing we are done */ + if (!fiemap->fm_mapped_extents) + break; /* if file has no segments, we are done */ + if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST) break; /* autosizing successful, we are done */ @@ -699,12 +703,12 @@ /*****************************************************************************/ #if !_POSIX_MAPPED_FILES -# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) -# define munmap(addr,length) (errno = ENOSYS, -1) +# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () +# define munmap(addr,length) EIO_ENOSYS () #endif #if !_POSIX_MEMORY_PROTECTION -# define mprotect(addr,len,prot) (errno = ENOSYS, -1) +# define mprotect(addr,len,prot) EIO_ENOSYS () # define PROT_NONE 0 # define PROT_WRITE 0 # define MAP_PRIVATE 0 @@ -957,6 +961,15 @@ const_iv (FIEMAP_EXTENT_MERGED) const_iv (FIEMAP_EXTENT_SHARED) + const_iv (SPLICE_F_MOVE) + const_iv (SPLICE_F_NONBLOCK) + const_iv (SPLICE_F_MORE) + const_iv (SPLICE_F_GIFT) + + const_iv (SEEK_DATA) + const_iv (SEEK_HOLE) + + /* libeio constants */ const_eio (SEEK_SET) const_eio (SEEK_CUR) const_eio (SEEK_END) @@ -975,6 +988,7 @@ const_eio (SYNC_FILE_RANGE_WAIT_AFTER) const_eio (FALLOC_FL_KEEP_SIZE) + const_eio (FALLOC_FL_PUNCH_HOLE) const_eio (READDIR_DENTS) const_eio (READDIR_DIRS_FIRST) @@ -1207,7 +1221,10 @@ { /* read: check type and grow scalar as necessary */ SvUPGRADE (data, SVt_PV); - svptr = SvGROW (data, len + dataoffset + 1); + if (SvLEN (data) >= SvCUR (data)) + svptr = SvGROW (data, len + dataoffset + 1); + else if (SvCUR (data) < len + dataoffset) + croak ("length + dataoffset outside of scalar, and cannot grow"); } { @@ -1520,7 +1537,7 @@ aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback=&PL_sv_undef) PPCODE: { - int fd = s_fileno_croak (fh, 0); + int fd = s_fileno_croak (fh, 0); dREQ; req->type = EIO_CUSTOM; @@ -1678,7 +1695,7 @@ RETVAL void -mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) +mmap (SV *scalar, size_t length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0) PPCODE: sv_unmagic (scalar, MMAP_MAGIC); { @@ -1721,7 +1738,7 @@ CODE: { STRLEN svlen; - void *addr = SvPVbyte (scalar, svlen); + void *addr = SvPVbyte (scalar, svlen); size_t len = SvUV (length); if (offset < 0) @@ -1767,7 +1784,7 @@ #if _POSIX_MEMLOCK_RANGE RETVAL = munlock (addr, len); #else - RETVAL = ((errno = ENOSYS), -1); + RETVAL = EIO_ENOSYS (); #endif } OUTPUT: @@ -1779,12 +1796,40 @@ #if _POSIX_MEMLOCK munlockall (); #else - RETVAL = -1; - errno = ENOSYS; + RETVAL = EIO_ENOSYS (); #endif OUTPUT: RETVAL +int +splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) + CODE: +{ +#if HAVE_LINUX_SPLICE + loff_t off_in_, off_out_; + RETVAL = splice ( + rfh, SvOK (off_in ) ? (off_in_ = SvVAL64 (off_in )), &off_in_ : 0, + wfh, SvOK (off_out) ? (off_out_ = SvVAL64 (off_out)), &off_out_ : 0, + length, flags + ); +#else + RETVAL = EIO_ENOSYS (); +#endif +} + OUTPUT: + RETVAL + +int +tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) + CODE: +#if HAVE_LINUX_SPLICE + RETVAL = tee (rfh, wfh, length, flags); +#else + RETVAL = EIO_ENOSYS (); +#endif + OUTPUT: + RETVAL + void _on_next_submit (SV *cb) CODE: SvREFCNT_dec (on_next_submit);