ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.210 by root, Fri Apr 6 11:39:25 2012 UTC vs.
Revision 1.213 by root, Tue Apr 10 05:01:33 2012 UTC

22#endif 22#endif
23 23
24#if __linux__ 24#if __linux__
25# include <linux/fs.h> 25# include <linux/fs.h>
26# ifdef FS_IOC_FIEMAP 26# ifdef FS_IOC_FIEMAP
27# include <linux/types.h>
27# include <linux/fiemap.h> 28# include <linux/fiemap.h>
28# define HAVE_FIEMAP 1 29# define HAVE_FIEMAP 1
29# endif 30# endif
30#endif 31#endif
31 32
164fiemap (eio_req *req) 165fiemap (eio_req *req)
165{ 166{
166 req->result = -1; 167 req->result = -1;
167 168
168#if HAVE_FIEMAP 169#if HAVE_FIEMAP
170 int count = req->int3;
171
172 /* heuristic: first try with 64 extents if we don't know how many, */
173 /* as most files have (hopefully) fewer than this many extents */
174 /* in fact, most should have <= 2, so maybe the 72 below is probably overkill */
175 if (count < 0)
176 count = 72; /* for what it's worth, 72 extents fit nicely into 4kb */
177
169 for (;;) 178 for (;;)
170 { 179 {
171 int count = req->int3;
172
173 if (count < 0)
174 {
175 struct fiemap fiemap;
176
177 fiemap.fm_start = req->offs;
178 fiemap.fm_length = req->size;
179 fiemap.fm_flags = req->int2;
180 fiemap.fm_extent_count = 0;
181
182 if (ioctl (req->int1, FS_IOC_FIEMAP, &fiemap))
183 return;
184
185 count = fiemap.fm_mapped_extents;
186 }
187
188 struct fiemap *fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); 180 struct fiemap *fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count);
189 errno = ENOMEM; 181 errno = ENOMEM;
190 if (!fiemap) 182 if (!fiemap)
191 return; 183 return;
192 184
204 if (req->int3 >= 0) 196 if (req->int3 >= 0)
205 break; /* when not autosizing we are done */ 197 break; /* when not autosizing we are done */
206 198
207 if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST) 199 if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST)
208 break; /* autosizing successful, we are done */ 200 break; /* autosizing successful, we are done */
201
202 fiemap->fm_flags = req->int2;
203 fiemap->fm_extent_count = 0;
204
205 if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap))
206 return;
207
208 count = fiemap->fm_mapped_extents;
209 209
210 free (fiemap); 210 free (fiemap);
211 } 211 }
212 212
213 req->result = 0; 213 req->result = 0;
545 break; 545 break;
546 546
547 case EIO_CUSTOM: 547 case EIO_CUSTOM:
548 if (req->feed == fiemap) 548 if (req->feed == fiemap)
549 { 549 {
550#if HAVE_FIEMAP
550 if (!req->result) 551 if (!req->result)
551 { 552 {
552 struct fiemap *fiemap = (struct fiemap *)req->ptr1; 553 struct fiemap *fiemap = (struct fiemap *)req->ptr1;
553 554
554 if (fiemap->fm_extent_count) 555 if (fiemap->fm_extent_count)
575 { 576 {
576 SvIV_set (sv_result, fiemap->fm_mapped_extents); 577 SvIV_set (sv_result, fiemap->fm_mapped_extents);
577 PUSHs (sv_result); 578 PUSHs (sv_result);
578 } 579 }
579 } 580 }
581#endif
580 } 582 }
581 else 583 else
582 PUSHs (sv_result); 584 PUSHs (sv_result);
583 break; 585 break;
584 586
696} 698}
697 699
698/*****************************************************************************/ 700/*****************************************************************************/
699 701
700#if !_POSIX_MAPPED_FILES 702#if !_POSIX_MAPPED_FILES
701# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) 703# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS ()
702# define munmap(addr,length) (errno = ENOSYS, -1) 704# define munmap(addr,length) EIO_ENOSYS ()
703#endif 705#endif
704 706
705#if !_POSIX_MEMORY_PROTECTION 707#if !_POSIX_MEMORY_PROTECTION
706# define mprotect(addr,len,prot) (errno = ENOSYS, -1) 708# define mprotect(addr,len,prot) EIO_ENOSYS ()
707# define PROT_NONE 0 709# define PROT_NONE 0
708# define PROT_WRITE 0 710# define PROT_WRITE 0
709# define MAP_PRIVATE 0 711# define MAP_PRIVATE 0
710# define MAP_SHARED 0 712# define MAP_SHARED 0
711# define MAP_FIXED 0 713# define MAP_FIXED 0
954 const_iv (FIEMAP_EXTENT_DATA_TAIL) 956 const_iv (FIEMAP_EXTENT_DATA_TAIL)
955 const_iv (FIEMAP_EXTENT_UNWRITTEN) 957 const_iv (FIEMAP_EXTENT_UNWRITTEN)
956 const_iv (FIEMAP_EXTENT_MERGED) 958 const_iv (FIEMAP_EXTENT_MERGED)
957 const_iv (FIEMAP_EXTENT_SHARED) 959 const_iv (FIEMAP_EXTENT_SHARED)
958 960
961 const_iv (SPLICE_F_MOVE)
962 const_iv (SPLICE_F_NONBLOCK)
963 const_iv (SPLICE_F_MORE)
964 const_iv (SPLICE_F_GIFT)
965
966 const_iv (SEEK_DATA)
967 const_iv (SEEK_HOLE)
968
969 /* libeio constants */
959 const_eio (SEEK_SET) 970 const_eio (SEEK_SET)
960 const_eio (SEEK_CUR) 971 const_eio (SEEK_CUR)
961 const_eio (SEEK_END) 972 const_eio (SEEK_END)
962 973
963 const_eio (MCL_FUTURE) 974 const_eio (MCL_FUTURE)
1164 1175
1165void 1176void
1166aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) 1177aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef)
1167 PPCODE: 1178 PPCODE:
1168{ 1179{
1169 STRLEN svlen;
1170 int fd = s_fileno_croak (fh, 0); 1180 int fd = s_fileno_croak (fh, 0);
1171 dREQ; 1181 dREQ;
1172 1182
1173 req->type = EIO_SEEK; 1183 req->type = EIO_SEEK;
1174 req->sv1 = newSVsv (fh); 1184 req->sv1 = newSVsv (fh);
1526 req->type = EIO_CUSTOM; 1536 req->type = EIO_CUSTOM;
1527 req->sv1 = newSVsv (fh); 1537 req->sv1 = newSVsv (fh);
1528 req->int1 = fd; 1538 req->int1 = fd;
1529 1539
1530 req->feed = fiemap; 1540 req->feed = fiemap;
1541#if HAVE_FIEMAP
1531 /* keep our fingers crossed that the next two types are 64 bit */ 1542 /* keep our fingers crossed that the next two types are 64 bit */
1532 req->offs = start; 1543 req->offs = start;
1533 req->size = SvOK (length) ? SvVAL64 (length) : ~0ULL; 1544 req->size = SvOK (length) ? SvVAL64 (length) : ~0ULL;
1534 req->int2 = flags; 1545 req->int2 = flags;
1535 req->int3 = SvOK (count) ? SvIV (count) : -1; 1546 req->int3 = SvOK (count) ? SvIV (count) : -1;
1547#endif
1536 1548
1537 REQ_SEND; 1549 REQ_SEND;
1538} 1550}
1539 1551
1540void 1552void
1763 addr = (void *)(((intptr_t)addr) + offset); 1775 addr = (void *)(((intptr_t)addr) + offset);
1764 eio_page_align (&addr, &len); 1776 eio_page_align (&addr, &len);
1765#if _POSIX_MEMLOCK_RANGE 1777#if _POSIX_MEMLOCK_RANGE
1766 RETVAL = munlock (addr, len); 1778 RETVAL = munlock (addr, len);
1767#else 1779#else
1768 RETVAL = ((errno = ENOSYS), -1); 1780 RETVAL = EIO_ENOSYS ();
1769#endif 1781#endif
1770} 1782}
1771 OUTPUT: 1783 OUTPUT:
1772 RETVAL 1784 RETVAL
1773 1785
1775munlockall () 1787munlockall ()
1776 CODE: 1788 CODE:
1777#if _POSIX_MEMLOCK 1789#if _POSIX_MEMLOCK
1778 munlockall (); 1790 munlockall ();
1779#else 1791#else
1780 RETVAL = -1; 1792 RETVAL = EIO_ENOSYS ();
1781 errno = ENOSYS;
1782#endif 1793#endif
1783 OUTPUT: 1794 OUTPUT:
1795 RETVAL
1796
1797int
1798splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags)
1799 CODE:
1800{
1801#if HAVE_LINUX_SPLICE
1802 loff_t off_in_, off_out_;
1803 RETVAL = splice (
1804 rfh, SvOK (off_in ) ? (off_in_ = SvVAL64 (off_in )), &off_in_ : 0,
1805 wfh, SvOK (off_out) ? (off_out_ = SvVAL64 (off_out)), &off_out_ : 0,
1806 length, flags
1807 );
1808#else
1809 RETVAL = EIO_ENOSYS ();
1810#endif
1811}
1812 OUTPUT:
1813 RETVAL
1814
1815int
1816tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags)
1817 CODE:
1818#if HAVE_LINUX_SPLICE
1819 RETVAL = tee (rfh, wfh, length, flags);
1820#else
1821 RETVAL = EIO_ENOSYS ();
1822#endif
1823 OUTPUT:
1784 RETVAL 1824 RETVAL
1785 1825
1786void _on_next_submit (SV *cb) 1826void _on_next_submit (SV *cb)
1787 CODE: 1827 CODE:
1788 SvREFCNT_dec (on_next_submit); 1828 SvREFCNT_dec (on_next_submit);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines