--- IO-AIO/README 2020/12/04 01:19:58 1.65 +++ IO-AIO/README 2024/02/16 21:20:52 1.71 @@ -230,6 +230,7 @@ IO::AIO::sendfile $ofh, $ifh, $offset, $count IO::AIO::fadvise $fh, $offset, $len, $advice + IO::AIO::fexecve $fh, $argv, $envp IO::AIO::mmap $scalar, $length, $prot, $flags[, $fh[, $offset]] IO::AIO::munmap $scalar @@ -251,14 +252,24 @@ IO::AIO::accept4 $r_fh, $sockaddr, $sockaddr_len, $flags IO::AIO::splice $r_fh, $r_off, $w_fh, $w_off, $length, $flags IO::AIO::tee $r_fh, $w_fh, $length, $flags + $actual_size = IO::AIO::pipesize $r_fh[, $new_size] ($rfh, $wfh) = IO::AIO::pipe2 [$flags] - $fh = IO::AIO::memfd_create $pathname[, $flags] + $fh = IO::AIO::eventfd [$initval, [$flags]] + $fh = IO::AIO::memfd_create $pathname[, $flags] + $fh = IO::AIO::timerfd_create $clockid[, $flags] ($cur_interval, $cur_value) = IO::AIO::timerfd_settime $fh, $flags, $new_interval, $nbw_value ($cur_interval, $cur_value) = IO::AIO::timerfd_gettime $fh + $fh = IO::AIO::pidfd_open $pid[, $flags] + $status = IO::AIO::pidfd_send_signal $pidfh, $signal[, $siginfo[, $flags]] + $fh = IO::AIO::pidfd_getfd $pidfh, $targetfd[, $flags] + + $retval = IO::AIO::mount $special, $path, $fstype, $flags = 0, $data = undef + $retval = IO::AIO::umount $path, $flags = 0 + API NOTES All the "aio_*" calls are more or less thin wrappers around the syscall with the same name (sans "aio_"). The arguments are similar or @@ -334,9 +345,6 @@ newly created filehandle for the file (or "undef" in case of an error). - The pathname passed to "aio_open" must be absolute. See API NOTES, - above, for an explanation. - The $flags argument is a bitmask. See the "Fcntl" module for a list. They are the same as used by "sysopen". @@ -499,9 +507,6 @@ available using "stat _" or "-s _" and other tests (with the exception of "-B" and "-T"). - The pathname passed to "aio_stat" must be absolute. See API NOTES, - above, for an explanation. - Currently, the stats are always 64-bit-stats, i.e. instead of returning an error when stat'ing a large file, the results will be silently truncated unless perl itself is compiled with large file @@ -854,8 +859,7 @@ Implementation notes. - The "aio_readdir" cannot be avoided, but "stat()"'ing every entry - can. + The "aio_readdir" cannot be avoided, but stat()'ing every entry can. If readdir returns file type information, then this is used directly to find directories. @@ -945,6 +949,10 @@ "FS_XFLAG_NODEFRAG", "FS_XFLAG_FILESTREAM", "FS_XFLAG_DAX", "FS_XFLAG_HASATTR", + "BLKROSET", "BLKROGET", "BLKRRPART", "BLKGETSIZE", "BLKFLSBUF", + "BLKRASET", "BLKRAGET", "BLKFRASET", "BLKFRAGET", "BLKSECTSET", + "BLKSECTGET", "BLKSSZGET", "BLKBSZGET", "BLKBSZSET", "BLKGETSIZE64", + aio_sync $callback->($status) Asynchronously call sync and call the callback when finished. @@ -1593,9 +1601,11 @@ In other words, this setting does not enforce a queue limit, but can be used to make poll functions block if the limit is exceeded. - This is a very bad function to use in interactive programs because - it blocks, and a bad way to reduce concurrency because it is - inexact: Better use an "aio_group" together with a feed callback. + This is a bad function to use in interactive programs because it + blocks, and a bad way to reduce concurrency because it is inexact. + If you need to issue many requests without being able to call a poll + function on demand, it is better to use an "aio_group" together with + a feed callback. Its main use is in scripts without an event loop - when you want to stat a lot of files, you can write something like this: @@ -1610,10 +1620,11 @@ IO::AIO::flush; The call to "poll_cb" inside the loop will normally return - instantly, but as soon as more thna 32 reqeusts are in-flight, it - will block until some requests have been handled. This keeps the - loop from pushing a large number of "aio_stat" requests onto the - queue. + instantly, allowing the loop to progress, but as soon as more than + 32 requests are in-flight, it will block until some requests have + been handled. This keeps the loop from pushing a large number of + "aio_stat" requests onto the queue (which, with many paths to stat, + can use up a lot of memory). The default value for "max_outstanding" is very large, so there is no practical limit on the number of outstanding requests. @@ -1728,6 +1739,42 @@ "Asynchronous I/O" route. Many of these have an asynchronous "aio_*" counterpart. + $retval = IO::AIO::fexecve $fh, $argv, $envp + A more-or-less direct equivalent to the POSIX "fexecve" functions, + which allows you to specify the program to be executed via a file + descriptor (or handle). Returns -1 and sets errno to "ENOSYS" if not + available. + + $retval = IO::AIO::mount $special, $path, $fstype, $flags = 0, $data = + undef + Calls the GNU/Linux mount syscall with the given arguments. All + except $flags are strings, and if $data is "undef", a "NULL" will be + passed. + + The following values for $flags are available: + + "IO::AIO::MS_RDONLY", "IO::AIO::MS_NOSUID", "IO::AIO::MS_NODEV", + "IO::AIO::MS_NOEXEC", "IO::AIO::MS_SYNCHRONOUS", + "IO::AIO::MS_REMOUNT", "IO::AIO::MS_MANDLOCK", + "IO::AIO::MS_DIRSYNC", "IO::AIO::MS_NOATIME", + "IO::AIO::MS_NODIRATIME", "IO::AIO::MS_BIND", "IO::AIO::MS_MOVE", + "IO::AIO::MS_REC", "IO::AIO::MS_SILENT", "IO::AIO::MS_POSIXACL", + "IO::AIO::MS_UNBINDABLE", "IO::AIO::MS_PRIVATE", + "IO::AIO::MS_SLAVE", "IO::AIO::MS_SHARED", "IO::AIO::MS_RELATIME", + "IO::AIO::MS_KERNMOUNT", "IO::AIO::MS_I_VERSION", + "IO::AIO::MS_STRICTATIME", "IO::AIO::MS_LAZYTIME", + "IO::AIO::MS_ACTIVE", "IO::AIO::MS_NOUSER", "IO::AIO::MS_RMT_MASK", + "IO::AIO::MS_MGC_VAL" and "IO::AIO::MS_MGC_MSK". + + $retval = IO::AIO::umount $path, $flags = 0 + Invokes the GNU/Linux "umount" or "umount2" syscalls. Always calls + "umount" if $flags is 0, otherwqise always tries to call "umount2". + + The following $flags are available: + + "IO::AIO::MNT_FORCE", "IO::AIO::MNT_DETACH", "IO::AIO::MNT_EXPIRE" + and "IO::AIO::UMOUNT_NOFOLLOW". + $numfd = IO::AIO::get_fdlimit Tries to find the current file descriptor limit and returns it, or "undef" and sets $! in case of an error. The limit is one larger @@ -1830,8 +1877,9 @@ "IO::AIO::MAP_LOCKED", "IO::AIO::MAP_NORESERVE", "IO::AIO::MAP_POPULATE", "IO::AIO::MAP_NONBLOCK", "IO::AIO::MAP_FIXED", "IO::AIO::MAP_GROWSDOWN", - "IO::AIO::MAP_32BIT", "IO::AIO::MAP_HUGETLB" or - "IO::AIO::MAP_STACK". + "IO::AIO::MAP_32BIT", "IO::AIO::MAP_HUGETLB", "IO::AIO::MAP_STACK", + "IO::AIO::MAP_FIXED_NOREPLACE", "IO::AIO::MAP_SHARED_VALIDATE", + "IO::AIO::MAP_SYNC" or "IO::AIO::MAP_UNINITIALIZED". If $fh is "undef", then a file descriptor of -1 is passed. @@ -1906,11 +1954,11 @@ To accept name-less sockets, use "undef" for $sockaddr and 0 for $sockaddr_maxlen. - The main reasons to use this syscall rather than portable - C«accept(2)> are that you can specify "SOCK_NONBLOCK" and/or - "SOCK_CLOEXEC" flags and you can accept name-less sockets by - specifying 0 for $sockaddr_maxlen, which is sadly not possible with - perl's interface to "accept". + The main reasons to use this syscall rather than portable accept(2) + are that you can specify "SOCK_NONBLOCK" and/or "SOCK_CLOEXEC" flags + and you can accept name-less sockets by specifying 0 for + $sockaddr_maxlen, which is sadly not possible with perl's interface + to "accept". IO::AIO::splice $r_fh, $r_off, $w_fh, $w_off, $length, $flags Calls the GNU/Linux splice(2) syscall, if available. If $r_off or @@ -1973,14 +2021,71 @@ Please refer to memfd_create(2) for more info on this call. The following $flags values are available: "IO::AIO::MFD_CLOEXEC", - "IO::AIO::MFD_ALLOW_SEALING" and "IO::AIO::MFD_HUGETLB". + "IO::AIO::MFD_ALLOW_SEALING", "IO::AIO::MFD_HUGETLB", + "IO::AIO::MFD_HUGETLB_2MB" and "IO::AIO::MFD_HUGETLB_1GB". Example: create a new memfd. my $fh = IO::AIO::memfd_create "somenameforprocfd", IO::AIO::MFD_CLOEXEC - or die "m,emfd_create: $!\n"; - =item $fh = IO::AIO::eventfd [$initval, [$flags]] + or die "memfd_create: $!\n"; + + $fh = IO::AIO::pidfd_open $pid[, $flags] + This is an interface to the Linux pidfd_open(2) system call. The + default for $flags is 0. + + On success, a new pidfd filehandle is returned (that is already set + to close-on-exec), otherwise returns "undef". If the syscall is + missing, fails with "ENOSYS". + + Example: open pid 6341 as pidfd. + + my $fh = IO::AIO::pidfd_open 6341 + or die "pidfd_open: $!\n"; + + $status = IO::AIO::pidfd_send_signal $pidfh, $signal[, $siginfo[, + $flags]] + This is an interface to the Linux pidfd_send_signal system call. The + default for $siginfo is "undef" and the default for $flags is 0. + + Returns the system call status. If the syscall is missing, fails + with "ENOSYS". + + When specified, $siginfo must be a reference to a hash with one or + more of the following members: + + code - the "si_code" member + pid - the "si_pid" member + uid - the "si_uid" member + value_int - the "si_value.sival_int" member + value_ptr - the "si_value.sival_ptr" member, specified as an integer + + Example: send a SIGKILL to the specified process. + + my $status = IO::AIO::pidfd_send_signal $pidfh, 9, undef + and die "pidfd_send_signal: $!\n"; + + Example: send a SIGKILL to the specified process with extra data. + + my $status = IO::AIO::pidfd_send_signal $pidfh, 9, { code => -1, value_int => 7 } + and die "pidfd_send_signal: $!\n"; + + $fh = IO::AIO::pidfd_getfd $pidfh, $targetfd[, $flags] + This is an interface to the Linux pidfd_getfd system call. The + default for $flags is 0. + + On success, returns a dup'ed copy of the target file descriptor + (specified as an integer) returned (that is already set to + close-on-exec), otherwise returns "undef". If the syscall is + missing, fails with "ENOSYS". + + Example: get a copy of standard error of another process and print + soemthing to it. + + my $errfh = IO::AIO::pidfd_getfd $pidfh, 2 + or die "pidfd_getfd: $!\n"; + print $errfh "stderr\n"; + $fh = IO::AIO::eventfd [$initval, [$flags]] This is a direct interface to the Linux eventfd(2) system call. The (unhelpful) defaults for $initval and $flags are 0 for both.