… | |
… | |
171 | use common::sense; |
171 | use common::sense; |
172 | |
172 | |
173 | use base 'Exporter'; |
173 | use base 'Exporter'; |
174 | |
174 | |
175 | BEGIN { |
175 | BEGIN { |
176 | our $VERSION = 4.35; |
176 | our $VERSION = 4.4; |
177 | |
177 | |
178 | our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close |
178 | our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close |
179 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx |
179 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx |
180 | aio_scandir aio_symlink aio_readlink aio_realpath aio_fcntl aio_ioctl |
180 | aio_scandir aio_symlink aio_readlink aio_realpath aio_fcntl aio_ioctl |
181 | aio_sync aio_fsync aio_syncfs aio_fdatasync aio_sync_file_range |
181 | aio_sync aio_fsync aio_syncfs aio_fdatasync aio_sync_file_range |
… | |
… | |
183 | aio_rename aio_rename2 aio_link aio_move aio_copy aio_group |
183 | aio_rename aio_rename2 aio_link aio_move aio_copy aio_group |
184 | aio_nop aio_mknod aio_load aio_rmtree aio_mkdir aio_chown |
184 | aio_nop aio_mknod aio_load aio_rmtree aio_mkdir aio_chown |
185 | aio_chmod aio_utime aio_truncate |
185 | aio_chmod aio_utime aio_truncate |
186 | aio_msync aio_mtouch aio_mlock aio_mlockall |
186 | aio_msync aio_mtouch aio_mlock aio_mlockall |
187 | aio_statvfs |
187 | aio_statvfs |
|
|
188 | aio_slurp |
188 | aio_wd); |
189 | aio_wd); |
189 | |
190 | |
190 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); |
191 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); |
191 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
192 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
192 | min_parallel max_parallel max_idle idle_timeout |
193 | min_parallel max_parallel max_idle idle_timeout |
… | |
… | |
277 | IO::AIO::idle_timeout $seconds |
278 | IO::AIO::idle_timeout $seconds |
278 | IO::AIO::max_outstanding $maxreqs |
279 | IO::AIO::max_outstanding $maxreqs |
279 | IO::AIO::nreqs |
280 | IO::AIO::nreqs |
280 | IO::AIO::nready |
281 | IO::AIO::nready |
281 | IO::AIO::npending |
282 | IO::AIO::npending |
|
|
283 | $nfd = IO::AIO::get_fdlimit [EXPERIMENTAL] |
282 | IO::AIO::min_fdlimit $nfd; |
284 | IO::AIO::min_fdlimit $nfd [EXPERIMENTAL] |
283 | |
285 | |
284 | IO::AIO::sendfile $ofh, $ifh, $offset, $count |
286 | IO::AIO::sendfile $ofh, $ifh, $offset, $count |
285 | IO::AIO::fadvise $fh, $offset, $len, $advice |
287 | IO::AIO::fadvise $fh, $offset, $len, $advice |
286 | IO::AIO::mmap $scalar, $length, $prot, $flags[, $fh[, $offset]] |
288 | IO::AIO::mmap $scalar, $length, $prot, $flags[, $fh[, $offset]] |
287 | IO::AIO::munmap $scalar |
289 | IO::AIO::munmap $scalar |
… | |
… | |
610 | namemax => 255, |
612 | namemax => 255, |
611 | frsize => 1024, |
613 | frsize => 1024, |
612 | fsid => 1810 |
614 | fsid => 1810 |
613 | } |
615 | } |
614 | |
616 | |
615 | Here is a (likely partial - send me updates!) list of fsid values used by |
|
|
616 | Linux - it is safe to hardcode these when C<$^O> is C<linux>: |
|
|
617 | |
|
|
618 | 0x0000adf5 adfs |
|
|
619 | 0x0000adff affs |
|
|
620 | 0x5346414f afs |
|
|
621 | 0x09041934 anon-inode filesystem |
|
|
622 | 0x00000187 autofs |
|
|
623 | 0x42465331 befs |
|
|
624 | 0x1badface bfs |
|
|
625 | 0x42494e4d binfmt_misc |
|
|
626 | 0x9123683e btrfs |
|
|
627 | 0x0027e0eb cgroupfs |
|
|
628 | 0xff534d42 cifs |
|
|
629 | 0x73757245 coda |
|
|
630 | 0x012ff7b7 coh |
|
|
631 | 0x28cd3d45 cramfs |
|
|
632 | 0x453dcd28 cramfs-wend (wrong endianness) |
|
|
633 | 0x64626720 debugfs |
|
|
634 | 0x00001373 devfs |
|
|
635 | 0x00001cd1 devpts |
|
|
636 | 0x0000f15f ecryptfs |
|
|
637 | 0x00414a53 efs |
|
|
638 | 0x0000137d ext |
|
|
639 | 0x0000ef53 ext2/ext3/ext4 |
|
|
640 | 0x0000ef51 ext2 |
|
|
641 | 0xf2f52010 f2fs |
|
|
642 | 0x00004006 fat |
|
|
643 | 0x65735546 fuseblk |
|
|
644 | 0x65735543 fusectl |
|
|
645 | 0x0bad1dea futexfs |
|
|
646 | 0x01161970 gfs2 |
|
|
647 | 0x47504653 gpfs |
|
|
648 | 0x00004244 hfs |
|
|
649 | 0xf995e849 hpfs |
|
|
650 | 0x00c0ffee hostfs |
|
|
651 | 0x958458f6 hugetlbfs |
|
|
652 | 0x2bad1dea inotifyfs |
|
|
653 | 0x00009660 isofs |
|
|
654 | 0x000072b6 jffs2 |
|
|
655 | 0x3153464a jfs |
|
|
656 | 0x6b414653 k-afs |
|
|
657 | 0x0bd00bd0 lustre |
|
|
658 | 0x0000137f minix |
|
|
659 | 0x0000138f minix 30 char names |
|
|
660 | 0x00002468 minix v2 |
|
|
661 | 0x00002478 minix v2 30 char names |
|
|
662 | 0x00004d5a minix v3 |
|
|
663 | 0x19800202 mqueue |
|
|
664 | 0x00004d44 msdos |
|
|
665 | 0x0000564c novell |
|
|
666 | 0x00006969 nfs |
|
|
667 | 0x6e667364 nfsd |
|
|
668 | 0x00003434 nilfs |
|
|
669 | 0x5346544e ntfs |
|
|
670 | 0x00009fa1 openprom |
|
|
671 | 0x7461636F ocfs2 |
|
|
672 | 0x00009fa0 proc |
|
|
673 | 0x6165676c pstorefs |
|
|
674 | 0x0000002f qnx4 |
|
|
675 | 0x68191122 qnx6 |
|
|
676 | 0x858458f6 ramfs |
|
|
677 | 0x52654973 reiserfs |
|
|
678 | 0x00007275 romfs |
|
|
679 | 0x67596969 rpc_pipefs |
|
|
680 | 0x73636673 securityfs |
|
|
681 | 0xf97cff8c selinux |
|
|
682 | 0x0000517b smb |
|
|
683 | 0x534f434b sockfs |
|
|
684 | 0x73717368 squashfs |
|
|
685 | 0x62656572 sysfs |
|
|
686 | 0x012ff7b6 sysv2 |
|
|
687 | 0x012ff7b5 sysv4 |
|
|
688 | 0x01021994 tmpfs |
|
|
689 | 0x15013346 udf |
|
|
690 | 0x00011954 ufs |
|
|
691 | 0x54190100 ufs byteswapped |
|
|
692 | 0x00009fa2 usbdevfs |
|
|
693 | 0x01021997 v9fs |
|
|
694 | 0xa501fcf5 vxfs |
|
|
695 | 0xabba1974 xenfs |
|
|
696 | 0x012ff7b4 xenix |
|
|
697 | 0x58465342 xfs |
|
|
698 | 0x012fd16d xia |
|
|
699 | |
|
|
700 | =item aio_utime $fh_or_path, $atime, $mtime, $callback->($status) |
617 | =item aio_utime $fh_or_path, $atime, $mtime, $callback->($status) |
701 | |
618 | |
702 | Works like perl's C<utime> function (including the special case of $atime |
619 | Works like perl's C<utime> function (including the special case of $atime |
703 | and $mtime being undef). Fractional times are supported if the underlying |
620 | and $mtime being undef). Fractional times are supported if the underlying |
704 | syscalls support them. |
621 | syscalls support them. |
… | |
… | |
925 | C<$type>'s are known, which can be used to speed up some algorithms. |
842 | C<$type>'s are known, which can be used to speed up some algorithms. |
926 | |
843 | |
927 | =back |
844 | =back |
928 | |
845 | |
929 | |
846 | |
|
|
847 | =item aio_slurp $pathname, $offset, $length, $data, $callback->($status) |
|
|
848 | |
|
|
849 | Opens, reads and closes the given file. The data is put into C<$data>, |
|
|
850 | which is resized as required. |
|
|
851 | |
|
|
852 | If C<$offset> is negative, then it is counted from the end of the file. |
|
|
853 | |
|
|
854 | If C<$length> is zero, then the remaining length of the file is |
|
|
855 | used. Also, in this case, the same limitations to modifying C<$data> apply |
|
|
856 | as when IO::AIO::mmap is used, i.e. it must only be modified in-place |
|
|
857 | with C<substr>. If the size of the file is known, specifying a non-zero |
|
|
858 | C<$length> results in a performance advantage. |
|
|
859 | |
|
|
860 | This request is similar to the older C<aio_load> request, but since it is |
|
|
861 | a single request, it might be more efficient to use. |
|
|
862 | |
|
|
863 | Example: load F</etc/passwd> into C<$passwd>. |
|
|
864 | |
|
|
865 | my $passwd; |
|
|
866 | aio_slurp "/etc/passwd", 0, 0, $passwd, sub { |
|
|
867 | $_[0] >= 0 |
|
|
868 | or die "/etc/passwd: $!\n"; |
|
|
869 | |
|
|
870 | printf "/etc/passwd is %d bytes long, and contains:\n", length $passwd; |
|
|
871 | print $passwd; |
|
|
872 | }; |
|
|
873 | IO::AIO::flush; |
|
|
874 | |
|
|
875 | |
930 | =item aio_load $pathname, $data, $callback->($status) |
876 | =item aio_load $pathname, $data, $callback->($status) |
931 | |
877 | |
932 | This is a composite request that tries to fully load the given file into |
878 | This is a composite request that tries to fully load the given file into |
933 | memory. Status is the same as with aio_read. |
879 | memory. Status is the same as with aio_read. |
|
|
880 | |
|
|
881 | Using C<aio_slurp> might be more efficient, as it is a single request. |
934 | |
882 | |
935 | =cut |
883 | =cut |
936 | |
884 | |
937 | sub aio_load($$;$) { |
885 | sub aio_load($$;$) { |
938 | my ($path, undef, $cb) = @_; |
886 | my ($path, undef, $cb) = @_; |
… | |
… | |
1482 | C<IO::AIO::FIEMAP_EXTENT_DATA_ENCRYPTED>, C<IO::AIO::FIEMAP_EXTENT_NOT_ALIGNED>, |
1430 | C<IO::AIO::FIEMAP_EXTENT_DATA_ENCRYPTED>, C<IO::AIO::FIEMAP_EXTENT_NOT_ALIGNED>, |
1483 | C<IO::AIO::FIEMAP_EXTENT_DATA_INLINE>, C<IO::AIO::FIEMAP_EXTENT_DATA_TAIL>, |
1431 | C<IO::AIO::FIEMAP_EXTENT_DATA_INLINE>, C<IO::AIO::FIEMAP_EXTENT_DATA_TAIL>, |
1484 | C<IO::AIO::FIEMAP_EXTENT_UNWRITTEN>, C<IO::AIO::FIEMAP_EXTENT_MERGED> or |
1432 | C<IO::AIO::FIEMAP_EXTENT_UNWRITTEN>, C<IO::AIO::FIEMAP_EXTENT_MERGED> or |
1485 | C<IO::AIO::FIEMAP_EXTENT_SHARED>. |
1433 | C<IO::AIO::FIEMAP_EXTENT_SHARED>. |
1486 | |
1434 | |
1487 | At the time of this writing (Linux 3.2), this requets is unreliable unless |
1435 | At the time of this writing (Linux 3.2), this request is unreliable unless |
1488 | C<$count> is C<undef>, as the kernel has all sorts of bugs preventing |
1436 | C<$count> is C<undef>, as the kernel has all sorts of bugs preventing |
1489 | it to return all extents of a range for files with large number of |
1437 | it to return all extents of a range for files with a large number of |
1490 | extents. The code works around all these issues if C<$count> is undef. |
1438 | extents. The code (only) works around all these issues if C<$count> is |
|
|
1439 | C<undef>. |
1491 | |
1440 | |
1492 | =item aio_group $callback->(...) |
1441 | =item aio_group $callback->(...) |
1493 | |
1442 | |
1494 | This is a very special aio request: Instead of doing something, it is a |
1443 | This is a very special aio request: Instead of doing something, it is a |
1495 | container for other aio requests, which is useful if you want to bundle |
1444 | container for other aio requests, which is useful if you want to bundle |
… | |
… | |
2069 | |
2018 | |
2070 | =over 4 |
2019 | =over 4 |
2071 | |
2020 | |
2072 | =item $numfd = IO::AIO::get_fdlimit |
2021 | =item $numfd = IO::AIO::get_fdlimit |
2073 | |
2022 | |
|
|
2023 | This function is I<EXPERIMENTAL> and subject to change. |
|
|
2024 | |
2074 | Tries to find the current file descriptor limit and returns it, or |
2025 | Tries to find the current file descriptor limit and returns it, or |
2075 | C<undef> and sets C<$!> in case of an error. The limit is one larger than |
2026 | C<undef> and sets C<$!> in case of an error. The limit is one larger than |
2076 | the highest valid file descriptor number. |
2027 | the highest valid file descriptor number. |
2077 | |
2028 | |
2078 | =item IO::AIO::min_fdlimit [$numfd] |
2029 | =item IO::AIO::min_fdlimit [$numfd] |
|
|
2030 | |
|
|
2031 | This function is I<EXPERIMENTAL> and subject to change. |
2079 | |
2032 | |
2080 | Try to increase the current file descriptor limit(s) to at least C<$numfd> |
2033 | Try to increase the current file descriptor limit(s) to at least C<$numfd> |
2081 | by changing the soft or hard file descriptor resource limit. If C<$numfd> |
2034 | by changing the soft or hard file descriptor resource limit. If C<$numfd> |
2082 | is missing, it will try to set a very high limit, although this is not |
2035 | is missing, it will try to set a very high limit, although this is not |
2083 | recommended when you know the actual minimum that you require. |
2036 | recommended when you know the actual minimum that you require. |