io_uring/opcode.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
//! Operation codes that can be used to construct [`squeue::Entry`](crate::squeue::Entry)s.
#![allow(clippy::new_without_default)]
use std::convert::TryInto;
use std::mem;
use std::os::unix::io::RawFd;
use crate::squeue::Entry;
use crate::squeue::Entry128;
use crate::sys;
use crate::types::{self, sealed};
macro_rules! assign_fd {
( $sqe:ident . fd = $opfd:expr ) => {
match $opfd {
sealed::Target::Fd(fd) => $sqe.fd = fd,
sealed::Target::Fixed(idx) => {
$sqe.fd = idx as _;
$sqe.flags |= crate::squeue::Flags::FIXED_FILE.bits();
}
}
};
}
macro_rules! opcode {
(@type impl sealed::UseFixed ) => {
sealed::Target
};
(@type impl sealed::UseFd ) => {
RawFd
};
(@type $name:ty ) => {
$name
};
(
$( #[$outer:meta] )*
pub struct $name:ident {
$( #[$new_meta:meta] )*
$( $field:ident : { $( $tnt:tt )+ } ),*
$(,)?
;;
$(
$( #[$opt_meta:meta] )*
$opt_field:ident : $opt_tname:ty = $default:expr
),*
$(,)?
}
pub const CODE = $opcode:expr;
$( #[$build_meta:meta] )*
pub fn build($self:ident) -> $entry:ty $build_block:block
) => {
$( #[$outer] )*
pub struct $name {
$( $field : opcode!(@type $( $tnt )*), )*
$( $opt_field : $opt_tname, )*
}
impl $name {
$( #[$new_meta] )*
#[inline]
pub fn new($( $field : $( $tnt )* ),*) -> Self {
$name {
$( $field: $field.into(), )*
$( $opt_field: $default, )*
}
}
/// The opcode of the operation. This can be passed to
/// [`Probe::is_supported`](crate::Probe::is_supported) to check if this operation is
/// supported with the current kernel.
pub const CODE: u8 = $opcode as _;
$(
$( #[$opt_meta] )*
#[inline]
pub const fn $opt_field(mut self, $opt_field: $opt_tname) -> Self {
self.$opt_field = $opt_field;
self
}
)*
$( #[$build_meta] )*
#[inline]
pub fn build($self) -> $entry $build_block
}
}
}
/// inline zeroed to improve codegen
#[inline(always)]
fn sqe_zeroed() -> sys::io_uring_sqe {
unsafe { mem::zeroed() }
}
opcode! {
/// Do not perform any I/O.
///
/// This is useful for testing the performance of the io_uring implementation itself.
#[derive(Debug)]
pub struct Nop { ;; }
pub const CODE = sys::IORING_OP_NOP;
pub fn build(self) -> Entry {
let Nop {} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
Entry(sqe)
}
}
opcode! {
/// Vectored read, equivalent to `preadv2(2)`.
#[derive(Debug)]
pub struct Readv {
fd: { impl sealed::UseFixed },
iovec: { *const libc::iovec },
len: { u32 },
;;
ioprio: u16 = 0,
offset: u64 = 0,
/// specified for read operations, contains a bitwise OR of per-I/O flags,
/// as described in the `preadv2(2)` man page.
rw_flags: types::RwFlags = 0,
buf_group: u16 = 0
}
pub const CODE = sys::IORING_OP_READV;
pub fn build(self) -> Entry {
let Readv {
fd,
iovec, len, offset,
ioprio, rw_flags,
buf_group
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = iovec as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
sqe.__bindgen_anon_4.buf_group = buf_group;
Entry(sqe)
}
}
opcode! {
/// Vectored write, equivalent to `pwritev2(2)`.
#[derive(Debug)]
pub struct Writev {
fd: { impl sealed::UseFixed },
iovec: { *const libc::iovec },
len: { u32 },
;;
ioprio: u16 = 0,
offset: u64 = 0,
/// specified for write operations, contains a bitwise OR of per-I/O flags,
/// as described in the `preadv2(2)` man page.
rw_flags: types::RwFlags = 0
}
pub const CODE = sys::IORING_OP_WRITEV;
pub fn build(self) -> Entry {
let Writev {
fd,
iovec, len, offset,
ioprio, rw_flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = iovec as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
Entry(sqe)
}
}
opcode! {
/// File sync, equivalent to `fsync(2)`.
///
/// Note that, while I/O is initiated in the order in which it appears in the submission queue,
/// completions are unordered. For example, an application which places a write I/O followed by
/// an fsync in the submission queue cannot expect the fsync to apply to the write. The two
/// operations execute in parallel, so the fsync may complete before the write is issued to the
/// storage. The same is also true for previously issued writes that have not completed prior to
/// the fsync.
#[derive(Debug)]
pub struct Fsync {
fd: { impl sealed::UseFixed },
;;
/// The `flags` bit mask may contain either 0, for a normal file integrity sync,
/// or [types::FsyncFlags::DATASYNC] to provide data sync only semantics.
/// See the descriptions of `O_SYNC` and `O_DSYNC` in the `open(2)` manual page for more information.
flags: types::FsyncFlags = types::FsyncFlags::empty()
}
pub const CODE = sys::IORING_OP_FSYNC;
pub fn build(self) -> Entry {
let Fsync { fd, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_3.fsync_flags = flags.bits();
Entry(sqe)
}
}
opcode! {
/// Read from a file into a fixed buffer that has been previously registered with
/// [`Submitter::register_buffers`](crate::Submitter::register_buffers).
///
/// The return values match those documented in the `preadv2(2)` man pages.
#[derive(Debug)]
pub struct ReadFixed {
fd: { impl sealed::UseFixed },
buf: { *mut u8 },
len: { u32 },
buf_index: { u16 },
;;
ioprio: u16 = 0,
/// The offset of the file to read from.
offset: u64 = 0,
/// Specified for read operations, contains a bitwise OR of per-I/O flags, as described in
/// the `preadv2(2)` man page.
rw_flags: types::RwFlags = 0
}
pub const CODE = sys::IORING_OP_READ_FIXED;
pub fn build(self) -> Entry {
let ReadFixed {
fd,
buf, len, offset,
buf_index,
ioprio, rw_flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
sqe.__bindgen_anon_4.buf_index = buf_index;
Entry(sqe)
}
}
opcode! {
/// Write to a file from a fixed buffer that have been previously registered with
/// [`Submitter::register_buffers`](crate::Submitter::register_buffers).
///
/// The return values match those documented in the `pwritev2(2)` man pages.
#[derive(Debug)]
pub struct WriteFixed {
fd: { impl sealed::UseFixed },
buf: { *const u8 },
len: { u32 },
buf_index: { u16 },
;;
ioprio: u16 = 0,
/// The offset of the file to write to.
offset: u64 = 0,
/// Specified for write operations, contains a bitwise OR of per-I/O flags, as described in
/// the `pwritev2(2)` man page.
rw_flags: types::RwFlags = 0
}
pub const CODE = sys::IORING_OP_WRITE_FIXED;
pub fn build(self) -> Entry {
let WriteFixed {
fd,
buf, len, offset,
buf_index,
ioprio, rw_flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
sqe.__bindgen_anon_4.buf_index = buf_index;
Entry(sqe)
}
}
opcode! {
/// Poll the specified fd.
///
/// Unlike poll or epoll without `EPOLLONESHOT`, this interface defaults to work in one shot mode.
/// That is, once the poll operation is completed, it will have to be resubmitted.
///
/// If multi is set, the poll will work in multi shot mode instead. That means it will
/// repeatedly trigger when the requested event becomes true, and hence multiple CQEs can be
/// generated from this single submission. The CQE flags field will have IORING_CQE_F_MORE set
/// on completion if the application should expect further CQE entries from the original
/// request. If this flag isn't set on completion, then the poll request has been terminated
/// and no further events will be generated. This mode is available since 5.13.
#[derive(Debug)]
pub struct PollAdd {
/// The bits that may be set in `flags` are defined in `<poll.h>`,
/// and documented in `poll(2)`.
fd: { impl sealed::UseFixed },
flags: { u32 },
;;
multi: bool = false
}
pub const CODE = sys::IORING_OP_POLL_ADD;
pub fn build(self) -> Entry {
let PollAdd { fd, flags, multi } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
if multi {
sqe.len = sys::IORING_POLL_ADD_MULTI;
}
#[cfg(target_endian = "little")] {
sqe.__bindgen_anon_3.poll32_events = flags;
}
#[cfg(target_endian = "big")] {
let x = flags << 16;
let y = flags >> 16;
let flags = x | y;
sqe.__bindgen_anon_3.poll32_events = flags;
}
Entry(sqe)
}
}
opcode! {
/// Remove an existing [poll](PollAdd) request.
///
/// If found, the `result` method of the `cqueue::Entry` will return 0.
/// If not found, `result` will return `-libc::ENOENT`.
#[derive(Debug)]
pub struct PollRemove {
user_data: { u64 }
;;
}
pub const CODE = sys::IORING_OP_POLL_REMOVE;
pub fn build(self) -> Entry {
let PollRemove { user_data } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = user_data;
Entry(sqe)
}
}
opcode! {
/// Sync a file segment with disk, equivalent to `sync_file_range(2)`.
#[derive(Debug)]
pub struct SyncFileRange {
fd: { impl sealed::UseFixed },
len: { u32 },
;;
/// the offset method holds the offset in bytes
offset: u64 = 0,
/// the flags method holds the flags for the command
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_SYNC_FILE_RANGE;
pub fn build(self) -> Entry {
let SyncFileRange {
fd,
len, offset,
flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.len = len;
sqe.__bindgen_anon_1.off = offset;
sqe.__bindgen_anon_3.sync_range_flags = flags;
Entry(sqe)
}
}
opcode! {
/// Send a message on a socket, equivalent to `send(2)`.
///
/// fd must be set to the socket file descriptor, addr must contains a pointer to the msghdr
/// structure, and flags holds the flags associated with the system call.
#[derive(Debug)]
pub struct SendMsg {
fd: { impl sealed::UseFixed },
msg: { *const libc::msghdr },
;;
ioprio: u16 = 0,
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_SENDMSG;
pub fn build(self) -> Entry {
let SendMsg { fd, msg, ioprio, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = msg as _;
sqe.len = 1;
sqe.__bindgen_anon_3.msg_flags = flags;
Entry(sqe)
}
}
opcode! {
/// Receive a message on a socket, equivalent to `recvmsg(2)`.
///
/// See also the description of [`SendMsg`].
#[derive(Debug)]
pub struct RecvMsg {
fd: { impl sealed::UseFixed },
msg: { *mut libc::msghdr },
;;
ioprio: u16 = 0,
flags: u32 = 0,
buf_group: u16 = 0
}
pub const CODE = sys::IORING_OP_RECVMSG;
pub fn build(self) -> Entry {
let RecvMsg { fd, msg, ioprio, flags, buf_group } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = msg as _;
sqe.len = 1;
sqe.__bindgen_anon_3.msg_flags = flags;
sqe.__bindgen_anon_4.buf_group = buf_group;
Entry(sqe)
}
}
opcode! {
/// Receive multiple messages on a socket, equivalent to `recvmsg(2)`.
///
/// Parameters:
/// msg: For this multishot variant of ResvMsg, only the msg_namelen and msg_controllen
/// fields are relevant.
/// buf_group: The id of the provided buffer pool to use for each received message.
///
/// See also the description of [`SendMsg`] and [`types::RecvMsgOut`].
///
/// The multishot version allows the application to issue a single receive request, which
/// repeatedly posts a CQE when data is available. It requires the MSG_WAITALL flag is not set.
/// Each CQE will take a buffer out of a provided buffer pool for receiving. The application
/// should check the flags of each CQE, regardless of its result. If a posted CQE does not have
/// the IORING_CQE_F_MORE flag set then the multishot receive will be done and the application
/// should issue a new request.
///
/// Unlike [`RecvMsg`], this multishot recvmsg will prepend a struct which describes the layout
/// of the rest of the buffer in combination with the initial msghdr structure submitted with
/// the request. Use [`types::RecvMsgOut`] to parse the data received and access its
/// components.
///
/// The recvmsg multishot variant is available since kernel 6.0.
#[derive(Debug)]
pub struct RecvMsgMulti {
fd: { impl sealed::UseFixed },
msg: { *const libc::msghdr },
buf_group: { u16 },
;;
ioprio: u16 = 0,
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_RECVMSG;
pub fn build(self) -> Entry {
let RecvMsgMulti { fd, msg, buf_group, ioprio, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = msg as _;
sqe.len = 1;
sqe.__bindgen_anon_3.msg_flags = flags;
sqe.__bindgen_anon_4.buf_group = buf_group;
sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
sqe.ioprio = ioprio | (sys::IORING_RECV_MULTISHOT as u16);
Entry(sqe)
}
}
opcode! {
/// Register a timeout operation.
///
/// A timeout will trigger a wakeup event on the completion ring for anyone waiting for events.
/// A timeout condition is met when either the specified timeout expires, or the specified number of events have completed.
/// Either condition will trigger the event.
/// The request will complete with `-ETIME` if the timeout got completed through expiration of the timer,
/// or 0 if the timeout got completed through requests completing on their own.
/// If the timeout was cancelled before it expired, the request will complete with `-ECANCELED`.
#[derive(Debug)]
pub struct Timeout {
timespec: { *const types::Timespec },
;;
/// `count` may contain a completion event count.
count: u32 = 0,
/// `flags` may contain [types::TimeoutFlags::ABS] for an absolute timeout value, or 0 for a relative timeout.
flags: types::TimeoutFlags = types::TimeoutFlags::empty()
}
pub const CODE = sys::IORING_OP_TIMEOUT;
pub fn build(self) -> Entry {
let Timeout { timespec, count, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = timespec as _;
sqe.len = 1;
sqe.__bindgen_anon_1.off = count as _;
sqe.__bindgen_anon_3.timeout_flags = flags.bits();
Entry(sqe)
}
}
// === 5.5 ===
opcode! {
/// Attempt to remove an existing [timeout operation](Timeout).
pub struct TimeoutRemove {
user_data: { u64 },
;;
}
pub const CODE = sys::IORING_OP_TIMEOUT_REMOVE;
pub fn build(self) -> Entry {
let TimeoutRemove { user_data } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = user_data;
Entry(sqe)
}
}
opcode! {
/// Attempt to update an existing [timeout operation](Timeout) with a new timespec.
/// The optional `count` value of the original timeout value cannot be updated.
pub struct TimeoutUpdate {
user_data: { u64 },
timespec: { *const types::Timespec },
;;
flags: types::TimeoutFlags = types::TimeoutFlags::empty()
}
pub const CODE = sys::IORING_OP_TIMEOUT_REMOVE;
pub fn build(self) -> Entry {
let TimeoutUpdate { user_data, timespec, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_1.off = timespec as _;
sqe.__bindgen_anon_2.addr = user_data;
sqe.__bindgen_anon_3.timeout_flags = flags.bits() | sys::IORING_TIMEOUT_UPDATE;
Entry(sqe)
}
}
opcode! {
/// Accept a new connection on a socket, equivalent to `accept4(2)`.
pub struct Accept {
fd: { impl sealed::UseFixed },
addr: { *mut libc::sockaddr },
addrlen: { *mut libc::socklen_t },
;;
file_index: Option<types::DestinationSlot> = None,
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_ACCEPT;
pub fn build(self) -> Entry {
let Accept { fd, addr, addrlen, file_index, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = addr as _;
sqe.__bindgen_anon_1.addr2 = addrlen as _;
sqe.__bindgen_anon_3.accept_flags = flags as _;
if let Some(dest) = file_index {
sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
}
Entry(sqe)
}
}
opcode! {
/// Attempt to cancel an already issued request.
pub struct AsyncCancel {
user_data: { u64 }
;;
// TODO flags
}
pub const CODE = sys::IORING_OP_ASYNC_CANCEL;
pub fn build(self) -> Entry {
let AsyncCancel { user_data } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = user_data;
Entry(sqe)
}
}
opcode! {
/// This request must be linked with another request through
/// [`Flags::IO_LINK`](crate::squeue::Flags::IO_LINK) which is described below.
/// Unlike [`Timeout`], [`LinkTimeout`] acts on the linked request, not the completion queue.
pub struct LinkTimeout {
timespec: { *const types::Timespec },
;;
flags: types::TimeoutFlags = types::TimeoutFlags::empty()
}
pub const CODE = sys::IORING_OP_LINK_TIMEOUT;
pub fn build(self) -> Entry {
let LinkTimeout { timespec, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = timespec as _;
sqe.len = 1;
sqe.__bindgen_anon_3.timeout_flags = flags.bits();
Entry(sqe)
}
}
opcode! {
/// Connect a socket, equivalent to `connect(2)`.
pub struct Connect {
fd: { impl sealed::UseFixed },
addr: { *const libc::sockaddr },
addrlen: { libc::socklen_t }
;;
}
pub const CODE = sys::IORING_OP_CONNECT;
pub fn build(self) -> Entry {
let Connect { fd, addr, addrlen } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = addr as _;
sqe.__bindgen_anon_1.off = addrlen as _;
Entry(sqe)
}
}
// === 5.6 ===
opcode! {
/// Preallocate or deallocate space to a file, equivalent to `fallocate(2)`.
pub struct Fallocate {
fd: { impl sealed::UseFixed },
len: { u64 },
;;
offset: u64 = 0,
mode: i32 = 0
}
pub const CODE = sys::IORING_OP_FALLOCATE;
pub fn build(self) -> Entry {
let Fallocate { fd, len, offset, mode } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = len;
sqe.len = mode as _;
sqe.__bindgen_anon_1.off = offset;
Entry(sqe)
}
}
opcode! {
/// Open a file, equivalent to `openat(2)`.
pub struct OpenAt {
dirfd: { impl sealed::UseFd },
pathname: { *const libc::c_char },
;;
file_index: Option<types::DestinationSlot> = None,
flags: i32 = 0,
mode: libc::mode_t = 0
}
pub const CODE = sys::IORING_OP_OPENAT;
pub fn build(self) -> Entry {
let OpenAt { dirfd, pathname, file_index, flags, mode } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = dirfd;
sqe.__bindgen_anon_2.addr = pathname as _;
sqe.len = mode;
sqe.__bindgen_anon_3.open_flags = flags as _;
if let Some(dest) = file_index {
sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
}
Entry(sqe)
}
}
opcode! {
/// Close a file descriptor, equivalent to `close(2)`.
///
/// Use a types::Fixed(fd) argument to close an io_uring direct descriptor.
pub struct Close {
fd: { impl sealed::UseFixed },
;;
}
pub const CODE = sys::IORING_OP_CLOSE;
pub fn build(self) -> Entry {
let Close { fd } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
match fd {
sealed::Target::Fd(fd) => sqe.fd = fd,
sealed::Target::Fixed(idx) => {
sqe.fd = 0;
sqe.__bindgen_anon_5.file_index = idx + 1;
}
}
Entry(sqe)
}
}
opcode! {
/// This command is an alternative to using
/// [`Submitter::register_files_update`](crate::Submitter::register_files_update) which then
/// works in an async fashion, like the rest of the io_uring commands.
pub struct FilesUpdate {
fds: { *const RawFd },
len: { u32 },
;;
offset: i32 = 0
}
pub const CODE = sys::IORING_OP_FILES_UPDATE;
pub fn build(self) -> Entry {
let FilesUpdate { fds, len, offset } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = fds as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset as _;
Entry(sqe)
}
}
opcode! {
/// Get file status, equivalent to `statx(2)`.
pub struct Statx {
dirfd: { impl sealed::UseFd },
pathname: { *const libc::c_char },
statxbuf: { *mut types::statx },
;;
flags: i32 = 0,
mask: u32 = 0
}
pub const CODE = sys::IORING_OP_STATX;
pub fn build(self) -> Entry {
let Statx {
dirfd, pathname, statxbuf,
flags, mask
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = dirfd;
sqe.__bindgen_anon_2.addr = pathname as _;
sqe.len = mask;
sqe.__bindgen_anon_1.off = statxbuf as _;
sqe.__bindgen_anon_3.statx_flags = flags as _;
Entry(sqe)
}
}
opcode! {
/// Issue the equivalent of a `pread(2)` or `pwrite(2)` system call
///
/// * `fd` is the file descriptor to be operated on,
/// * `addr` contains the buffer in question,
/// * `len` contains the length of the IO operation,
///
/// These are non-vectored versions of the `IORING_OP_READV` and `IORING_OP_WRITEV` opcodes.
/// See also `read(2)` and `write(2)` for the general description of the related system call.
///
/// Available since 5.6.
pub struct Read {
fd: { impl sealed::UseFixed },
buf: { *mut u8 },
len: { u32 },
;;
/// `offset` contains the read or write offset.
///
/// If `fd` does not refer to a seekable file, `offset` must be set to zero.
/// If `offset` is set to `-1`, the offset will use (and advance) the file position,
/// like the `read(2)` and `write(2)` system calls.
offset: u64 = 0,
ioprio: u16 = 0,
rw_flags: types::RwFlags = 0,
buf_group: u16 = 0
}
pub const CODE = sys::IORING_OP_READ;
pub fn build(self) -> Entry {
let Read {
fd,
buf, len, offset,
ioprio, rw_flags,
buf_group
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
sqe.__bindgen_anon_4.buf_group = buf_group;
Entry(sqe)
}
}
opcode! {
/// Issue the equivalent of a `pread(2)` or `pwrite(2)` system call
///
/// * `fd` is the file descriptor to be operated on,
/// * `addr` contains the buffer in question,
/// * `len` contains the length of the IO operation,
///
/// These are non-vectored versions of the `IORING_OP_READV` and `IORING_OP_WRITEV` opcodes.
/// See also `read(2)` and `write(2)` for the general description of the related system call.
///
/// Available since 5.6.
pub struct Write {
fd: { impl sealed::UseFixed },
buf: { *const u8 },
len: { u32 },
;;
/// `offset` contains the read or write offset.
///
/// If `fd` does not refer to a seekable file, `offset` must be set to zero.
/// If `offsett` is set to `-1`, the offset will use (and advance) the file position,
/// like the `read(2)` and `write(2)` system calls.
offset: u64 = 0,
ioprio: u16 = 0,
rw_flags: types::RwFlags = 0
}
pub const CODE = sys::IORING_OP_WRITE;
pub fn build(self) -> Entry {
let Write {
fd,
buf, len, offset,
ioprio, rw_flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
Entry(sqe)
}
}
opcode! {
/// Predeclare an access pattern for file data, equivalent to `posix_fadvise(2)`.
pub struct Fadvise {
fd: { impl sealed::UseFixed },
len: { libc::off_t },
advice: { i32 },
;;
offset: u64 = 0,
}
pub const CODE = sys::IORING_OP_FADVISE;
pub fn build(self) -> Entry {
let Fadvise { fd, len, advice, offset } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.len = len as _;
sqe.__bindgen_anon_1.off = offset;
sqe.__bindgen_anon_3.fadvise_advice = advice as _;
Entry(sqe)
}
}
opcode! {
/// Give advice about use of memory, equivalent to `madvise(2)`.
pub struct Madvise {
addr: { *const libc::c_void },
len: { libc::off_t },
advice: { i32 },
;;
}
pub const CODE = sys::IORING_OP_MADVISE;
pub fn build(self) -> Entry {
let Madvise { addr, len, advice } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = addr as _;
sqe.len = len as _;
sqe.__bindgen_anon_3.fadvise_advice = advice as _;
Entry(sqe)
}
}
opcode! {
/// Send a message on a socket, equivalent to `send(2)`.
pub struct Send {
fd: { impl sealed::UseFixed },
buf: { *const u8 },
len: { u32 },
;;
flags: i32 = 0,
/// Set the destination address, for sending from an unconnected socket.
///
/// When set, `dest_addr_len` must be set as well.
/// See also `man 3 io_uring_prep_send_set_addr`.
dest_addr: *const libc::sockaddr = core::ptr::null(),
dest_addr_len: libc::socklen_t = 0,
}
pub const CODE = sys::IORING_OP_SEND;
pub fn build(self) -> Entry {
let Send { fd, buf, len, flags, dest_addr, dest_addr_len } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = buf as _;
sqe.__bindgen_anon_1.addr2 = dest_addr as _;
sqe.__bindgen_anon_5.__bindgen_anon_1.addr_len = dest_addr_len as _;
sqe.len = len;
sqe.__bindgen_anon_3.msg_flags = flags as _;
Entry(sqe)
}
}
opcode! {
/// Receive a message from a socket, equivalent to `recv(2)`.
pub struct Recv {
fd: { impl sealed::UseFixed },
buf: { *mut u8 },
len: { u32 },
;;
flags: i32 = 0,
buf_group: u16 = 0
}
pub const CODE = sys::IORING_OP_RECV;
pub fn build(self) -> Entry {
let Recv { fd, buf, len, flags, buf_group } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_3.msg_flags = flags as _;
sqe.__bindgen_anon_4.buf_group = buf_group;
Entry(sqe)
}
}
opcode! {
/// Receive multiple messages from a socket, equivalent to `recv(2)`.
///
/// Parameter:
/// buf_group: The id of the provided buffer pool to use for each received message.
///
/// MSG_WAITALL should not be set in flags.
///
/// The multishot version allows the application to issue a single receive request, which
/// repeatedly posts a CQE when data is available. Each CQE will take a buffer out of a
/// provided buffer pool for receiving. The application should check the flags of each CQE,
/// regardless of its result. If a posted CQE does not have the IORING_CQE_F_MORE flag set then
/// the multishot receive will be done and the application should issue a new request.
///
/// Multishot variants are available since kernel 6.0.
pub struct RecvMulti {
fd: { impl sealed::UseFixed },
buf_group: { u16 },
;;
flags: i32 = 0,
}
pub const CODE = sys::IORING_OP_RECV;
pub fn build(self) -> Entry {
let RecvMulti { fd, buf_group, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_3.msg_flags = flags as _;
sqe.__bindgen_anon_4.buf_group = buf_group;
sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
sqe.ioprio = sys::IORING_RECV_MULTISHOT as _;
Entry(sqe)
}
}
opcode! {
/// Open a file, equivalent to `openat2(2)`.
pub struct OpenAt2 {
dirfd: { impl sealed::UseFd },
pathname: { *const libc::c_char },
how: { *const types::OpenHow }
;;
file_index: Option<types::DestinationSlot> = None,
}
pub const CODE = sys::IORING_OP_OPENAT2;
pub fn build(self) -> Entry {
let OpenAt2 { dirfd, pathname, how, file_index } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = dirfd;
sqe.__bindgen_anon_2.addr = pathname as _;
sqe.len = mem::size_of::<sys::open_how>() as _;
sqe.__bindgen_anon_1.off = how as _;
if let Some(dest) = file_index {
sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
}
Entry(sqe)
}
}
opcode! {
/// Modify an epoll file descriptor, equivalent to `epoll_ctl(2)`.
pub struct EpollCtl {
epfd: { impl sealed::UseFixed },
fd: { impl sealed::UseFd },
op: { i32 },
ev: { *const types::epoll_event },
;;
}
pub const CODE = sys::IORING_OP_EPOLL_CTL;
pub fn build(self) -> Entry {
let EpollCtl { epfd, fd, op, ev } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = epfd);
sqe.__bindgen_anon_2.addr = ev as _;
sqe.len = op as _;
sqe.__bindgen_anon_1.off = fd as _;
Entry(sqe)
}
}
// === 5.7 ===
opcode! {
/// Splice data to/from a pipe, equivalent to `splice(2)`.
///
/// if `fd_in` refers to a pipe, `off_in` must be `-1`;
/// The description of `off_in` also applied to `off_out`.
pub struct Splice {
fd_in: { impl sealed::UseFixed },
off_in: { i64 },
fd_out: { impl sealed::UseFixed },
off_out: { i64 },
len: { u32 },
;;
/// see man `splice(2)` for description of flags.
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_SPLICE;
pub fn build(self) -> Entry {
let Splice { fd_in, off_in, fd_out, off_out, len, mut flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd_out);
sqe.len = len;
sqe.__bindgen_anon_1.off = off_out as _;
sqe.__bindgen_anon_5.splice_fd_in = match fd_in {
sealed::Target::Fd(fd) => fd,
sealed::Target::Fixed(idx) => {
flags |= sys::SPLICE_F_FD_IN_FIXED;
idx as _
}
};
sqe.__bindgen_anon_2.splice_off_in = off_in as _;
sqe.__bindgen_anon_3.splice_flags = flags;
Entry(sqe)
}
}
opcode! {
/// Register `nbufs` buffers that each have the length `len` with ids starting from `bid` in the
/// group `bgid` that can be used for any request. See
/// [`BUFFER_SELECT`](crate::squeue::Flags::BUFFER_SELECT) for more info.
pub struct ProvideBuffers {
addr: { *mut u8 },
len: { i32 },
nbufs: { u16 },
bgid: { u16 },
bid: { u16 }
;;
}
pub const CODE = sys::IORING_OP_PROVIDE_BUFFERS;
pub fn build(self) -> Entry {
let ProvideBuffers { addr, len, nbufs, bgid, bid } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = nbufs as _;
sqe.__bindgen_anon_2.addr = addr as _;
sqe.len = len as _;
sqe.__bindgen_anon_1.off = bid as _;
sqe.__bindgen_anon_4.buf_group = bgid;
Entry(sqe)
}
}
opcode! {
/// Remove some number of buffers from a buffer group. See
/// [`BUFFER_SELECT`](crate::squeue::Flags::BUFFER_SELECT) for more info.
pub struct RemoveBuffers {
nbufs: { u16 },
bgid: { u16 }
;;
}
pub const CODE = sys::IORING_OP_REMOVE_BUFFERS;
pub fn build(self) -> Entry {
let RemoveBuffers { nbufs, bgid } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = nbufs as _;
sqe.__bindgen_anon_4.buf_group = bgid;
Entry(sqe)
}
}
// === 5.8 ===
opcode! {
/// Duplicate pipe content, equivalent to `tee(2)`.
pub struct Tee {
fd_in: { impl sealed::UseFixed },
fd_out: { impl sealed::UseFixed },
len: { u32 }
;;
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_TEE;
pub fn build(self) -> Entry {
let Tee { fd_in, fd_out, len, mut flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd_out);
sqe.len = len;
sqe.__bindgen_anon_5.splice_fd_in = match fd_in {
sealed::Target::Fd(fd) => fd,
sealed::Target::Fixed(idx) => {
flags |= sys::SPLICE_F_FD_IN_FIXED;
idx as _
}
};
sqe.__bindgen_anon_3.splice_flags = flags;
Entry(sqe)
}
}
// === 5.11 ===
opcode! {
/// Shut down all or part of a full duplex connection on a socket, equivalent to `shutdown(2)`.
/// Available since kernel 5.11.
pub struct Shutdown {
fd: { impl sealed::UseFixed },
how: { i32 },
;;
}
pub const CODE = sys::IORING_OP_SHUTDOWN;
pub fn build(self) -> Entry {
let Shutdown { fd, how } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.len = how as _;
Entry(sqe)
}
}
opcode! {
// Change the name or location of a file, equivalent to `renameat2(2)`.
// Available since kernel 5.11.
pub struct RenameAt {
olddirfd: { impl sealed::UseFd },
oldpath: { *const libc::c_char },
newdirfd: { impl sealed::UseFd },
newpath: { *const libc::c_char },
;;
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_RENAMEAT;
pub fn build(self) -> Entry {
let RenameAt {
olddirfd, oldpath,
newdirfd, newpath,
flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = olddirfd;
sqe.__bindgen_anon_2.addr = oldpath as _;
sqe.len = newdirfd as _;
sqe.__bindgen_anon_1.off = newpath as _;
sqe.__bindgen_anon_3.rename_flags = flags;
Entry(sqe)
}
}
opcode! {
// Delete a name and possible the file it refers to, equivalent to `unlinkat(2)`.
// Available since kernel 5.11.
pub struct UnlinkAt {
dirfd: { impl sealed::UseFd },
pathname: { *const libc::c_char },
;;
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_UNLINKAT;
pub fn build(self) -> Entry {
let UnlinkAt { dirfd, pathname, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = dirfd;
sqe.__bindgen_anon_2.addr = pathname as _;
sqe.__bindgen_anon_3.unlink_flags = flags as _;
Entry(sqe)
}
}
// === 5.15 ===
opcode! {
/// Make a directory, equivalent to `mkdirat(2)`.
pub struct MkDirAt {
dirfd: { impl sealed::UseFd },
pathname: { *const libc::c_char },
;;
mode: libc::mode_t = 0
}
pub const CODE = sys::IORING_OP_MKDIRAT;
pub fn build(self) -> Entry {
let MkDirAt { dirfd, pathname, mode } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = dirfd;
sqe.__bindgen_anon_2.addr = pathname as _;
sqe.len = mode;
Entry(sqe)
}
}
opcode! {
/// Create a symlink, equivalent to `symlinkat(2)`.
pub struct SymlinkAt {
newdirfd: { impl sealed::UseFd },
target: { *const libc::c_char },
linkpath: { *const libc::c_char },
;;
}
pub const CODE = sys::IORING_OP_SYMLINKAT;
pub fn build(self) -> Entry {
let SymlinkAt { newdirfd, target, linkpath } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = newdirfd;
sqe.__bindgen_anon_2.addr = target as _;
sqe.__bindgen_anon_1.addr2 = linkpath as _;
Entry(sqe)
}
}
opcode! {
/// Create a hard link, equivalent to `linkat(2)`.
pub struct LinkAt {
olddirfd: { impl sealed::UseFd },
oldpath: { *const libc::c_char },
newdirfd: { impl sealed::UseFd },
newpath: { *const libc::c_char },
;;
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_LINKAT;
pub fn build(self) -> Entry {
let LinkAt { olddirfd, oldpath, newdirfd, newpath, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = olddirfd as _;
sqe.__bindgen_anon_2.addr = oldpath as _;
sqe.len = newdirfd as _;
sqe.__bindgen_anon_1.addr2 = newpath as _;
sqe.__bindgen_anon_3.hardlink_flags = flags as _;
Entry(sqe)
}
}
// === 5.18 ===
opcode! {
/// Send a message (with data) to a target ring.
pub struct MsgRingData {
ring_fd: { impl sealed::UseFd },
result: { i32 },
user_data: { u64 },
user_flags: { Option<u32> },
;;
opcode_flags: u32 = 0
}
pub const CODE = sys::IORING_OP_MSG_RING;
pub fn build(self) -> Entry {
let MsgRingData { ring_fd, result, user_data, user_flags, opcode_flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.__bindgen_anon_2.addr = sys::IORING_MSG_DATA.into();
sqe.fd = ring_fd;
sqe.len = result as u32;
sqe.__bindgen_anon_1.off = user_data;
sqe.__bindgen_anon_3.msg_ring_flags = opcode_flags;
if let Some(flags) = user_flags {
sqe.__bindgen_anon_5.file_index = flags;
unsafe {sqe.__bindgen_anon_3.msg_ring_flags |= sys::IORING_MSG_RING_FLAGS_PASS};
}
Entry(sqe)
}
}
// === 5.19 ===
opcode! {
/// Attempt to cancel an already issued request, receiving a cancellation
/// builder, which allows for the new cancel criterias introduced since
/// 5.19.
pub struct AsyncCancel2 {
builder: { types::CancelBuilder }
;;
}
pub const CODE = sys::IORING_OP_ASYNC_CANCEL;
pub fn build(self) -> Entry {
let AsyncCancel2 { builder } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = builder.to_fd();
sqe.__bindgen_anon_2.addr = builder.user_data.unwrap_or(0);
sqe.__bindgen_anon_3.cancel_flags = builder.flags.bits();
Entry(sqe)
}
}
opcode! {
/// A file/device-specific 16-byte command, akin (but not equivalent) to `ioctl(2)`.
pub struct UringCmd16 {
fd: { impl sealed::UseFixed },
cmd_op: { u32 },
;;
/// The `buf_index` is an index into an array of fixed buffers,
/// and is only valid if fixed buffers were registered.
buf_index: Option<u16> = None,
/// Arbitrary command data.
cmd: [u8; 16] = [0u8; 16]
}
pub const CODE = sys::IORING_OP_URING_CMD;
pub fn build(self) -> Entry {
let UringCmd16 { fd, cmd_op, cmd, buf_index } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_1.__bindgen_anon_1.cmd_op = cmd_op;
unsafe { *sqe.__bindgen_anon_6.cmd.as_mut().as_mut_ptr().cast::<[u8; 16]>() = cmd };
if let Some(buf_index) = buf_index {
sqe.__bindgen_anon_4.buf_index = buf_index;
unsafe {
sqe.__bindgen_anon_3.uring_cmd_flags |= sys::IORING_URING_CMD_FIXED;
}
}
Entry(sqe)
}
}
opcode! {
/// A file/device-specific 80-byte command, akin (but not equivalent) to `ioctl(2)`.
pub struct UringCmd80 {
fd: { impl sealed::UseFixed },
cmd_op: { u32 },
;;
/// The `buf_index` is an index into an array of fixed buffers,
/// and is only valid if fixed buffers were registered.
buf_index: Option<u16> = None,
/// Arbitrary command data.
cmd: [u8; 80] = [0u8; 80]
}
pub const CODE = sys::IORING_OP_URING_CMD;
pub fn build(self) -> Entry128 {
let UringCmd80 { fd, cmd_op, cmd, buf_index } = self;
let cmd1 = cmd[..16].try_into().unwrap();
let cmd2 = cmd[16..].try_into().unwrap();
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_1.__bindgen_anon_1.cmd_op = cmd_op;
unsafe { *sqe.__bindgen_anon_6.cmd.as_mut().as_mut_ptr().cast::<[u8; 16]>() = cmd1 };
if let Some(buf_index) = buf_index {
sqe.__bindgen_anon_4.buf_index = buf_index;
unsafe {
sqe.__bindgen_anon_3.uring_cmd_flags |= sys::IORING_URING_CMD_FIXED;
}
}
Entry128(Entry(sqe), cmd2)
}
}
opcode! {
/// Create an endpoint for communication, equivalent to `socket(2)`.
///
/// If the `file_index` argument is set, the resulting socket is
/// directly mapped to the given fixed-file slot instead of being
/// returned as a normal file descriptor. The application must first
/// have registered a file table, and the target slot should fit into
/// it.
///
/// Available since 5.19.
pub struct Socket {
domain: { i32 },
socket_type: { i32 },
protocol: { i32 },
;;
file_index: Option<types::DestinationSlot> = None,
flags: types::RwFlags = 0,
}
pub const CODE = sys::IORING_OP_SOCKET;
pub fn build(self) -> Entry {
let Socket { domain, socket_type, protocol, file_index, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = domain as _;
sqe.__bindgen_anon_1.off = socket_type as _;
sqe.len = protocol as _;
sqe.__bindgen_anon_3.rw_flags = flags;
if let Some(dest) = file_index {
sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
}
Entry(sqe)
}
}
opcode! {
/// Accept multiple new connections on a socket.
///
/// Set the `allocate_file_index` property if fixed file table entries should be used.
///
/// Available since 5.19.
pub struct AcceptMulti {
fd: { impl sealed::UseFixed },
;;
allocate_file_index: bool = false,
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_ACCEPT;
pub fn build(self) -> Entry {
let AcceptMulti { fd, allocate_file_index, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = sys::IORING_ACCEPT_MULTISHOT as u16;
// No out SockAddr is passed for the multishot accept case.
// The user should perform a syscall to get any resulting connection's remote address.
sqe.__bindgen_anon_3.accept_flags = flags as _;
if allocate_file_index {
sqe.__bindgen_anon_5.file_index = sys::IORING_FILE_INDEX_ALLOC as u32;
}
Entry(sqe)
}
}
// === 6.0 ===
opcode! {
/// Send a message (with fixed FD) to a target ring.
pub struct MsgRingSendFd {
ring_fd: { impl sealed::UseFd },
fixed_slot_src: { types::Fixed },
dest_slot_index: { types::DestinationSlot },
user_data: { u64 },
;;
opcode_flags: u32 = 0
}
pub const CODE = sys::IORING_OP_MSG_RING;
pub fn build(self) -> Entry {
let MsgRingSendFd { ring_fd, fixed_slot_src, dest_slot_index, user_data, opcode_flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.__bindgen_anon_2.addr = sys::IORING_MSG_SEND_FD.into();
sqe.fd = ring_fd;
sqe.__bindgen_anon_1.off = user_data;
unsafe { sqe.__bindgen_anon_6.__bindgen_anon_1.as_mut().addr3 = fixed_slot_src.0 as u64 };
sqe.__bindgen_anon_5.file_index = dest_slot_index.kernel_index_arg();
sqe.__bindgen_anon_3.msg_ring_flags = opcode_flags;
Entry(sqe)
}
}
// === 6.0 ===
opcode! {
/// Send a zerocopy message on a socket, equivalent to `send(2)`.
///
/// When `dest_addr` is non-zero it points to the address of the target with `dest_addr_len`
/// specifying its size, turning the request into a `sendto(2)`
///
/// A fixed (pre-mapped) buffer can optionally be used from pre-mapped buffers that have been
/// previously registered with [`Submitter::register_buffers`](crate::Submitter::register_buffers).
///
/// This operation might result in two completion queue entries.
/// See the `IORING_OP_SEND_ZC` section at [io_uring_enter][] for the exact semantics.
/// Notifications posted by this operation can be checked with [notif](crate::cqueue::notif).
///
/// [io_uring_enter]: https://man7.org/linux/man-pages/man2/io_uring_enter.2.html
pub struct SendZc {
fd: { impl sealed::UseFixed },
buf: { *const u8 },
len: { u32 },
;;
/// The `buf_index` is an index into an array of fixed buffers, and is only valid if fixed
/// buffers were registered.
///
/// The buf and len arguments must fall within a region specified by buf_index in the
/// previously registered buffer. The buffer need not be aligned with the start of the
/// registered buffer.
buf_index: Option<u16> = None,
dest_addr: *const libc::sockaddr = core::ptr::null(),
dest_addr_len: libc::socklen_t = 0,
flags: i32 = 0,
zc_flags: u16 = 0,
}
pub const CODE = sys::IORING_OP_SEND_ZC;
pub fn build(self) -> Entry {
let SendZc { fd, buf, len, buf_index, dest_addr, dest_addr_len, flags, zc_flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_3.msg_flags = flags as _;
sqe.ioprio = zc_flags;
if let Some(buf_index) = buf_index {
sqe.__bindgen_anon_4.buf_index = buf_index;
sqe.ioprio |= sys::IORING_RECVSEND_FIXED_BUF as u16;
}
sqe.__bindgen_anon_1.addr2 = dest_addr as _;
sqe.__bindgen_anon_5.__bindgen_anon_1.addr_len = dest_addr_len as _;
Entry(sqe)
}
}
// === 6.1 ===
opcode! {
/// Send a zerocopy message on a socket, equivalent to `send(2)`.
///
/// fd must be set to the socket file descriptor, addr must contains a pointer to the msghdr
/// structure, and flags holds the flags associated with the system call.
#[derive(Debug)]
pub struct SendMsgZc {
fd: { impl sealed::UseFixed },
msg: { *const libc::msghdr },
;;
ioprio: u16 = 0,
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_SENDMSG_ZC;
pub fn build(self) -> Entry {
let SendMsgZc { fd, msg, ioprio, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = msg as _;
sqe.len = 1;
sqe.__bindgen_anon_3.msg_flags = flags;
Entry(sqe)
}
}
// === 6.7 ===
opcode! {
/// Wait on a futex, like but not equivalant to `futex(2)`'s `FUTEX_WAIT_BITSET`.
///
/// Wait on a futex at address `futex` and which still has the value `val` and with `futex2(2)`
/// flags of `futex_flags`. `musk` can be set to a specific bitset mask, which will be matched
/// by the waking side to decide who to wake up. To always get woken, an application may use
/// `FUTEX_BITSET_MATCH_ANY` (truncated to futex bits). `futex_flags` follows the `futex2(2)`
/// flags, not the `futex(2)` v1 interface flags. `flags` are currently unused and hence `0`
/// must be passed.
#[derive(Debug)]
pub struct FutexWait {
futex: { *const u32 },
val: { u64 },
mask: { u64 },
futex_flags: { u32 },
;;
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_FUTEX_WAIT;
pub fn build(self) -> Entry {
let FutexWait { futex, val, mask, futex_flags, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = futex_flags as _;
sqe.__bindgen_anon_2.addr = futex as usize as _;
sqe.__bindgen_anon_1.off = val;
unsafe { sqe.__bindgen_anon_6.__bindgen_anon_1.as_mut().addr3 = mask };
sqe.__bindgen_anon_3.futex_flags = flags;
Entry(sqe)
}
}
opcode! {
/// Wake up waiters on a futex, like but not equivalant to `futex(2)`'s `FUTEX_WAKE_BITSET`.
///
/// Wake any waiters on the futex indicated by `futex` and at most `val` futexes. `futex_flags`
/// indicates the `futex2(2)` modifier flags. If a given bitset for who to wake is desired,
/// then that must be set in `mask`. Use `FUTEX_BITSET_MATCH_ANY` (truncated to futex bits) to
/// match any waiter on the given futex. `flags` are currently unused and hence `0` must be
/// passed.
#[derive(Debug)]
pub struct FutexWake {
futex: { *const u32 },
val: { u64 },
mask: { u64 },
futex_flags: { u32 },
;;
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_FUTEX_WAKE;
pub fn build(self) -> Entry {
let FutexWake { futex, val, mask, futex_flags, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = futex_flags as _;
sqe.__bindgen_anon_2.addr = futex as usize as _;
sqe.__bindgen_anon_1.off = val;
unsafe { sqe.__bindgen_anon_6.__bindgen_anon_1.as_mut().addr3 = mask };
sqe.__bindgen_anon_3.futex_flags = flags;
Entry(sqe)
}
}
opcode! {
/// Wait on multiple futexes.
///
/// Wait on multiple futexes at the same time. Futexes are given by `futexv` and `nr_futex` is
/// the number of futexes in that array. Unlike `FutexWait`, the desired bitset mask and values
/// are passed in `futexv`. `flags` are currently unused and hence `0` must be passed.
#[derive(Debug)]
pub struct FutexWaitV {
futexv: { *const types::FutexWaitV },
nr_futex: { u32 },
;;
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_FUTEX_WAITV;
pub fn build(self) -> Entry {
let FutexWaitV { futexv, nr_futex, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.__bindgen_anon_2.addr = futexv as usize as _;
sqe.len = nr_futex;
sqe.__bindgen_anon_3.futex_flags = flags;
Entry(sqe)
}
}
// === 6.8 ===
opcode! {
/// Install a fixed file descriptor
///
/// Turns a direct descriptor into a regular file descriptor that can be later used by regular
/// system calls that take a normal raw file descriptor
#[derive(Debug)]
pub struct FixedFdInstall {
fd: { types::Fixed },
file_flags: { u32 },
;;
}
pub const CODE = sys::IORING_OP_FIXED_FD_INSTALL;
pub fn build(self) -> Entry {
let FixedFdInstall { fd, file_flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = fd.0 as _;
sqe.flags = crate::squeue::Flags::FIXED_FILE.bits();
sqe.__bindgen_anon_3.install_fd_flags = file_flags;
Entry(sqe)
}
}
// === 6.9 ===
opcode! {
/// Perform file truncation, equivalent to `ftruncate(2)`.
#[derive(Debug)]
pub struct Ftruncate {
fd: { impl sealed::UseFixed },
len: { u64 },
;;
}
pub const CODE = sys::IORING_OP_FTRUNCATE;
pub fn build(self) -> Entry {
let Ftruncate { fd, len } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_1.off = len;
Entry(sqe)
}
}
// === 6.10 ===
opcode! {
/// Send a bundle of messages on a socket in a single request.
pub struct SendBundle {
fd: { impl sealed::UseFixed },
buf_group: { u16 },
;;
flags: i32 = 0,
len: u32 = 0
}
pub const CODE = sys::IORING_OP_SEND;
pub fn build(self) -> Entry {
let SendBundle { fd, len, flags, buf_group } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.len = len;
sqe.__bindgen_anon_3.msg_flags = flags as _;
sqe.ioprio |= sys::IORING_RECVSEND_BUNDLE as u16;
sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
sqe.__bindgen_anon_4.buf_group = buf_group;
Entry(sqe)
}
}
opcode! {
/// Receive a bundle of buffers from a socket.
///
/// Parameter
/// buf_group: The id of the provided buffer pool to use for the bundle.
///
/// Note that as of kernel 6.10 first recv always gets a single buffer, while second
/// obtains the bundle of remaining buffers. This behavior may change in the future.
///
/// Bundle variant is available since kernel 6.10
pub struct RecvBundle {
fd: { impl sealed::UseFixed },
buf_group: { u16 },
;;
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_RECV;
pub fn build(self) -> Entry {
let RecvBundle { fd, buf_group, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_3.msg_flags = flags as _;
sqe.__bindgen_anon_4.buf_group = buf_group;
sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
sqe.ioprio |= sys::IORING_RECVSEND_BUNDLE as u16;
Entry(sqe)
}
}
opcode! {
/// Receive multiple messages from a socket as a bundle.
///
/// Parameter:
/// buf_group: The id of the provided buffer pool to use for each received message.
///
/// MSG_WAITALL should not be set in flags.
///
/// The multishot version allows the application to issue a single receive request, which
/// repeatedly posts a CQE when data is available. Each CQE will take a bundle of buffers
/// out of a provided buffer pool for receiving. The application should check the flags of each CQE,
/// regardless of its result. If a posted CQE does not have the IORING_CQE_F_MORE flag set then
/// the multishot receive will be done and the application should issue a new request.
///
/// Note that as of kernel 6.10 first CQE always gets a single buffer, while second
/// obtains the bundle of remaining buffers. This behavior may change in the future.
///
/// Multishot bundle variant is available since kernel 6.10.
pub struct RecvMultiBundle {
fd: { impl sealed::UseFixed },
buf_group: { u16 },
;;
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_RECV;
pub fn build(self) -> Entry {
let RecvMultiBundle { fd, buf_group, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_3.msg_flags = flags as _;
sqe.__bindgen_anon_4.buf_group = buf_group;
sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
sqe.ioprio = sys::IORING_RECV_MULTISHOT as _;
sqe.ioprio |= sys::IORING_RECVSEND_BUNDLE as u16;
Entry(sqe)
}
}